Solved

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

Posted on 2004-10-02
11
211 Views
Last Modified: 2010-05-18
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
Comment
Question by:marijanav
  • 4
  • 2
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12207946
>>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
 

Author Comment

by:marijanav
ID: 12208003
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12208079
>>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
 

Author Comment

by:marijanav
ID: 12208098
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12208213
Tell me a bit about, say one of those conversions
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 108 total points
ID: 12208234
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
 
LVL 92

Expert Comment

by:objects
ID: 12209247
you shouldn't need to change your data ata ll, just change your color model as required.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 107 total points
ID: 12209269
0
 
LVL 2

Expert Comment

by:shah1d1698
ID: 12322065
>>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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 90
GUI builder for Eclipse? 8 27
ForLoop Example 3 40
hibernate jars 4 0
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now