Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

HELP: reading image and converting from one color format to another

HI,

i have an urgent question that i don't even know how to start dealign with.

i have an image that i cast as BufferedImage. i am supposed to convert it into another color format. problem is i  have no idea how ot manipulate images. i knwo that i am supposed to use WritableRaster etc. but i don't know how to apply this

specific question: how do i read all the pixels and then manipulate them

can some one help me please

m
0
marijanav
Asked:
marijanav
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
CEHJCommented:
>>how do i read all the pixels and then manipulate them


http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#getRGB(int, int, int, int, int[], int, int)
0
 
marijanavAuthor Commented:
so

in order to get the color i would do a double for loop for the image and store getRGB values inside a double array

then how would i convert them to other colors?

also inside getRGB (....) how do we determine the offset, when we work with the whole image?
0
 
CEHJCommented:
>>in order to get the color i would do a double for loop

No - read the docs for that method

>>then how would i convert them to other colors?

What have you in mind to do here?

>>how do we determine the offset, when we work with the whole image?

Not sure what you mean there
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
marijanavAuthor Commented:
i would like to go from an rgb color space to xyz to lab


i know the theory behind this and i have the formulae i need but i don't know how to apply this. let's just say my programming skills are pretty pathetic
0
 
CEHJCommented:
Tell me a bit about, say one of those conversions
0
 
CEHJCommented:
Got to go out now but have a look at ColorSpace and ColorModel:

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/color/ColorSpace.html#toCIEXYZ(float[])
0
 
objectsCommented:
you shouldn't need to change your data ata ll, just change your color model as required.
0
 
shah1d1698Commented:
>>specific question: how do i read all the pixels and then manipulate them


Here is some help..

First create an Image object(Image img) and with that instance try the following code..

 

public void handlesinglepixel(int x, int y, int pixel) {
 int alpha = (pixel >> 24) & 0xff;
 int red   = (pixel >> 16) & 0xff;
 int green = (pixel >>  8) & 0xff;
 int blue  = (pixel      ) & 0xff;
 // Deal with the pixel as necessary...
 }

 public void handlepixels(Image img, int x, int y, int w, int h) {
 int[] pixels = new int[w * h];
 PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
 try {
     pg.grabPixels();
 } catch (InterruptedException e) {
     System.err.println("interrupted waiting for pixels!");
     return;
 }
 if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
     System.err.println("image fetch aborted or errored");
     return;
 }
 for (int j = 0; j < h; j++) {
     for (int i = 0; i < w; i++) {
  handlesinglepixel(x+i, y+j, pixels[j * w + i]);
     }
 }
 }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now