MemoryImageSource with byte[] (creating a workable color model)

332 Views Asked by At

I have no problem setting up an image from an array of integers. (As the integer version of MemoryImageSource can be instantiated with a far simpler constructor).

I tried:

    ComponentColorModel model = new ComponentColorModel(
        ColorSpace.getInstance(ColorSpace.CS_sRGB),
        false,
        false,
        ComponentColorModel.OPAQUE,
        DataBuffer.TYPE_BYTE);
    ImageProducer ip = new MemoryImageSource(width, height, model, bytes, 0, width);

But the image seems to be empty (totally transparent). I tried with image data and without alpha and also constructed the model with and without alpha channel. - No image shows.

There is no problem at all if I convert my byte[] to int[] and use the constructor:

MemoryImageSource(int w, int h, int[] pix, int off, int scan)

... but won't work with:

MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)

I'm probably having the color model wrong, but even then I expect to see some distorted pixel data (espacially with usong ComponentColorModel.OPAQUE).

0

There are 0 best solutions below