This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 41124
    
  45
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 - my free Android networking tools app
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: 41124
    
  45
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...
 
Don't get me started about those stupid light bulbs.
 
subject: Getting RGB values
 
Similar Threads
serilizing BufferedImage
changing gray pixels....
Pasting Images Problem
getting problem in creating an image from int array
Dealing with images