File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Getting RGB values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting RGB values " Watch "Getting RGB values " New topic
Author

Getting RGB values

Hafsa Hosani
Greenhorn

Joined: Mar 09, 2009
Posts: 3
Hi there,

Can somebody help me in writing this program. I want a simple program that takes an image of jpg format as an input
and return its pixels RGB values representation.

import java.awt.*;
import java.awt.image.*;
import java.util.*;
class JPEGshow extends Frame {
...
static public void main(String[] args) {
if (args.length == 1) new JPEGshow(args[0]);
else System.err.println("usage: java JPEGshow <image file>");
}
}

Where can I put getRGB method in the above code if it helps solving the problem?
kannan vinayagam Duraiswamy
Ranch Hand

Joined: Jan 12, 2009
Posts: 52




Kannan.DV
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
You can use the javax.imageio.ImageIO.read method to open JPEG files. That will create a BufferedImage object which has two "getRGB" methods for either getting an individual pixel's value, or all values of a rectangular area inside of it.


Ping & DNS - updated with new look and Ping home screen widget
Hafsa Hosani
Greenhorn

Joined: Mar 09, 2009
Posts: 3
kannan vinayagam Duraiswamy thanks for your reply.
Ulf Dittmer, my images are in circular shape (iris images), will it work with circular images or not?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Well, JPEGs are rectangular by definition. It's up to your code to decide which parts of the image are interesting and which are not. But since you can retrieve RGB values for each individual pixel that's not an impediment.
Hafsa Hosani
Greenhorn

Joined: Mar 09, 2009
Posts: 3
OK. Thanks alot...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting RGB values
 
Similar Threads
Pasting Images Problem
getting problem in creating an image from int array
serilizing BufferedImage
Dealing with images
changing gray pixels....