File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Java Imaging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Imaging" Watch "Java Imaging" New topic
Author

Java Imaging

Rex Raleigh
Greenhorn

Joined: Dec 11, 2010
Posts: 9
i'm a beginner in java and i would like to ask how do you operate on images? from what i've searched, it's basically using the BufferedImage class to operate on those images.
i've seen examples such as making filters and all, and i'm quite familiar with some of those. (i've had some little image processing experience using c++)

i would like to know some basics when it comes to handling images. from loading them from a file, to storing them in arrays, and changing pixel values, etc.

thanks.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
You would use the javax.imageio.ImageIO class to read and write images from files. That would provide you with a BufferedImage object which you can either manipulate directly (through the getRGB and setRGB methods), or you can access its Raster (through the getRaster method), which gives you more ways to manipulate the image.

Note that the values handled by getRGB and setRGB contain all data for a single pixel in one integer: red value, blue value, green value, and alpha value (if the image has one). So if you intend to do work on the individual pixel values, you'll have to extract those values from the integer, transform them as desired, and then put them back together.

This will also help: http://download.oracle.com/javase/tutorial/2d/images/index.html It explains how to perform higher-order image manipulations like drawing geometric shapes.
Rex Raleigh
Greenhorn

Joined: Dec 11, 2010
Posts: 9
is it possible to extract pixel values from an image and store them in a 2d array?

for example, i will load an image and then store it's pixel values to an array. lets say the image size is 100x100 pixels. the first pixel of that image should be at the coordinate (1,1) and thus, stored in an array, say, image[0][0]. from that array, i will try to make some manipulations such as comparing values and such.

i'm really not sure on how to implement this in java since i'm just starting out and re-learning the language.

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
is it possible to extract pixel values from an image and store them in a 2d array?


Why do you need to store the pixels in a 2D array? The pixels are already stored in the BufferedImage class. You can access them just like a 2D Array by using the getRGB(x, y) method as suggested earlier. You could always write code to copy them to a 2D array but I don't see the reason for this.
Rex Raleigh
Greenhorn

Joined: Dec 11, 2010
Posts: 9
the reason i want to do this is i'll try to represent the image as an array of coordinates. i would also try to include only selected parts of the whole picture, thus requiring me to select only certain pixels in the given image.

i'm not that familiar on how to use the BufferedImage class yet, so maybe you could enlighten me on how does it store and operate on the pixels. thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2204
    
    7
so maybe you could enlighten me on how does it store and operate on the pixels. thanks.


For the 3rd time is uses the getRGB(...) and setRGB(...) methods.

What don't you understand about that?
Rex Raleigh
Greenhorn

Joined: Dec 11, 2010
Posts: 9
okay i'll take a look at those methods. it would be great if you could provide samples on how to use them so i could understand them better.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Have you checked the BufferedImage Javadocs? Have you checked getRGB and setRGB, especially their parameters?

Now that you have ( ), how would you get a value at a specific point from an array? And from a BufferedImage?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: Java Imaging