Solved

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

Posted on 2004-10-02
11
202 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 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

17 Experts available now in Live!

Get 1:1 Help Now