• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting RGB values

 
Hafsa Hosani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hafsa Hosani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Thanks alot...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic