Alpha raster

I’m trying to recolour images and have run into a slight problem.

colourImage holds a block of the relevant colour and greyImage holds a greyscale image. The following two lines are supposed to put the greyscale image into colourImage’s alpha raster. It is then drawn onto a destination image.

WritableRaster wr = colourImage.getAlphaRaster();
wr.setRect(shadeImage.getData());

width and height are ints containing the width and height of the image.

The problem is, it seems to be scaling the shadeImage horizontally to several times its original width when it does so.

Anyone have any idea why?

At a guess, the shadeImage data is actually coming out as RGBA data with all the components the same (i.e. - grey) and alpha of 255. The data internally is actually expanded to 32bit data (maybe 24bit, Im not sure) - hence the 4x the width you expect, its reading 4 bytes per pixel and copying to a dest which uses 1 byte per pixel.
You should run through the data and write the bytes into the alpha raster by just reading a single component of the greyscale image (as the R = G = B for shades of grey.)

Hope this helps,

  • Dom

That was the problem, it works fine now.

Thanks a lot.