Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image manipulation question

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a button image that I need to modify in my code.

The code will need to increase the size of the image, and add new pixel data to it.

I imagine the code will need to:
1. convert the jpg image into a data array
2. manipulate the data array
3. convert back to jpg

Can anyone advise me how to perform steps 1 and 3. Any example code would be also be much appreciated.

Cheers,
James
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is this "pixel data" coming from? Capturing something from the screen? Performing a transformation of some sort? Making a composite of two images? It's very simple to insert a filter to make all red pixels blue, for example, and does not involve a "data array".
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya Ken,

The original image is a jpeg file.

Basically, the operation from step 2 will be to elongate the image (but not 'stretch', as this will distort the curves in the image).

The new image will be bigger than the original and have new pixel data added to it. (The new pixel data to be inserted will actually be taken from the original image.)

Cheers,
James
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use ImageIO to read and write images.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Hodgkiss:
Hiya Ken,

The original image is a jpeg file.

Basically, the operation from step 2 will be to elongate the image (but not 'stretch', as this will distort the curves in the image).

The new image will be bigger than the original and have new pixel data added to it. (The new pixel data to be inserted will actually be taken from the original image.)

Cheers,
James


Well you can use ImageIO as mentioned. JAI also has a "fileload" operation that will return a PlanarImage. How you're going to elongate this is beyond me. I'm no expert on image manipulation but it seems to me you're going to need to cut it up, stretch the portion(s) being extended, then put it all back together.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the replies. I've now come across the PixelGrabber and MemoryImageSource APIs - which look just the job.

Cheers,
James
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Hodgkiss:
Many thanks for the replies. I've now come across the PixelGrabber and MemoryImageSource APIs - which look just the job.


Hmmm... Most folks find BufferedImage and the 2D API both easier to work with and more powerful to boot. Take the 2D Graphics tutorial: http://java.sun.com/docs/books/tutorial/2d/index.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic