How to convert images to a standard format

S

sunsetbrew

I have been trying so many things to load in images from mutiple
formats (PNG, GIF, JEPG and TIFF), resize and save them out as JPEG's.
I am currently using JAI to load in the images via a stream. But when
I save them, they sometimes end up corrupt or turn blueish and etc.
This really seems to be a problem with PNG files the most. I have
learned a lot about image formats, but converting images with many
bands and etc seems non-trival. My "almost" successful attempt at
getting a standard format was

public PlanarImage applyRGBFilter(PlanarImage in) {

BufferedImage bufImg = new
BufferedImage(in.getWidth(),in.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bufImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.drawImage(in.getAsBufferedImage(),0,0,null);
g2.dispose();
return PlanarImage.wrapRenderedImage(bufImg);

}

Any idea??? I have spent over a week trying to figure this out and
reading and searching for data. This post is a last resort for me. I
hope someone can help.

Thanks,
Thomas
 
R

Roedy Green

I have
learned a lot about image formats, but converting images with many
bands and etc seems non-trival.

I gather what you do is convert internally to some raster format where
you can view it on the screen. Have you discovered if the problem is
converting TO or FROM that raster format?

Conceptually your problem is coming up with correcting function to
remap the R G B intensities before saving. The solution may lie in
http://mindprod.com/jgloss/gamma.html

Perhaps there is some direct way of influencing the corrections in the
conversion process.
 
S

sunsetbrew

What i am trying to do is take an image file that can already be viewed
in a web browser and modify it (resize and etc) as needed.

On some images, is works fine, but on many PNG (and possible others),
the colors change when viewed in the same web browser.

I have found out that the change seems to occur by simply rmoving the
4th band (bandselect {0,1,2}). So I believe the question may be one
about band reduction.

But then there are other formats where the bands take on different
meanings.

The optimal solution would be if I could convert into RGB 3 band
format. I just don't know how to make that happen in a generic way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top