DrawImage with IndexColorModel with transparency
Here is my problem: I would like to apply transformations (translation + rotation + clip) to a BufferedImage based on an IndexColorModel with transparency (index 0 is my transparent pixel, index 1 is black, index 2 is white, etc.)
The original image (i.e. before the transformations) is created this way and then evaluated by reading data from the file:
// Color Model
IndexColorModel cm;
cm = new IndexColorModel(7, length, colors[0], colors[1], colors[2], 0);
// Source image.
BufferedImage source;
source = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, cm);
Then a new image is created like this:
AffineTransform tr = new AffineTransform();
// Valuating AffineTransform [β¦]
IndexColorModel cm2 = (IndexColorModel ) source.getColorModel();
BufferedImage result = new BufferedImage( newWidth, newHeight, BufferedImage.TYPE_BYTE_INDEXED, cm2);
Graphics2D graphics = (Graphics2D) result.getGraphics();
Polygon polygon = new Polygon (xList, yList, points.length) ;
graphics.setClip(polygon);
graphics.drawImage(source, tr, null);
The conversions of the BufferedImage result are fine, but the problem is with colors: transparent pixels are transparent (ok), but black pixels now appear even more transparent. As my IndexColorMap was poorly read. Using TYPE_INT_ARGB seems to be ok, but not possible for me because the images are very large (memory limitation).
I did another test with AffineTransformOp like this:
AffineTransformOp op = new AffineTransform(tr, AffineTransformOp.TYPE_NEAREST_NEIGBOR);
op.filter(source, result);
The display is ok (black - black;)) but I don't know how to apply the clipping operation. However, it makes me think the IndexColorModel is ok.
What am I doing wrong? ... What's the problem with drawing an image with an IndexColorModel with transparency? Could you please help me find a solution to this problem, given my memory limitations? ...
source to share
No one has answered this question yet
See similar questions:
or similar: