Solved

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

Posted on 2004-10-02
11
235 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
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!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal Reports Licensing Questions 4 87
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 71
Bot application - advice 3 81
Java array 21 150
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 video teaches viewers about errors in exception handling.

752 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