Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-10-02
11
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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
 
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 432 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 428 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

Industry Leaders: 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!

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

730 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