1

I have a color indexed TIFF image (8-bits) and I want to convert it to a RGB 24-bits image (not indexed). What would be the way to do that?

I'm using JMagick. In a weird way, it works fine for indexed 8-bits images that are grayscale when i use:

image.transformRgbImage(info.getColorspace());

even if the image, though not indexed any more, is still 8-bits after that, which is lucky as it is grayscale and should actually be 8-bits. The weird stuff is that the transformRgbImage() performs that although I'd rather expect it to convert the image to a 24-bits one. Anyway...

The same way doesn't work for a color indexed 8-bits image. I just don't know how to use the JMagick API to achieve that goal. I tried setting:

image.setDepth(24);

or:

info.setDepth(24);

but both result in an EXCEPTION_ACCESS_VIOLATION. When I set:

info.setDepth(32);

no exception is raised, 1) but the image is 32-bits, which shouldn't be, and 2) it is all black (1 unique color). Why does the setDepth(24) raises such an exception?? How should I do?

Thanks in advance for your help.

Andrea
  • 11,801
  • 17
  • 65
  • 72
Erwann
  • 95
  • 2
  • 11
  • Do you have transparency in your image? The only difference between 24 bit and 32 bit is transparency. Indexed images also support transparency (one index for transparent pixels). – vadimvolk Oct 25 '13 at 10:16
  • I think not... The only soft I got is GIMP and it doesn't display the background as a checked pattern as it would do for a transparent channel. Plus, my image is a TIFF. TIFF cannot have a transparent color, can they? – Erwann Oct 25 '13 at 12:36

1 Answers1

2

I dont know about jmagick, but generally once you created an image object its properties are fixed (size and color model).

You don't change an images properties, you create a new image with the desired target properties and paint your original image into the new image. In plain core java you would simply do it like this:

public BufferedImage toRGB(Image i) {
    BufferedImage rgb = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_RGB);
    rgb.createGraphics().drawImage(i, 0, 0, null);
    return rgb;
}
Durandal
  • 19,919
  • 4
  • 36
  • 70
  • I was trying the hard way whereas it was that simple! Thank you very much for your helpful answer. Now I've got to do is reset the resolution and compression settings, which were lost in the process. – Erwann Oct 28 '13 at 09:46