Good day all,
First off, I am quite new to Android, and I am currently trying to make an image-editing application. I have run into a problem whereby, if I move a semi-transparent image over another image, the image behind is not drawn (on Canvas). Note that this is only if I do not change/set the Paint object's Alpha (which I don't want to do - if I change alpha values of an image, I want them to be 'permanently' changed (for saving purposes), not only visually).
Basically, I have the following:
//Set up of paint object
paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); // I've tried a couple of these (DST_ATOP and OVERLAY)
//paint.setColor(0x808fd2ea); - Messed around with this too, just to see
Here is the loop I am currently using to just manually change the alpha of each pixel, currently alpha = 120 (±50% transparency)
for(int y = 0; y < bmp.getHeight(); ++y)
{
int newPixelAlpha = (alpha << 24);
for (int x = 0; x < bmp.getWidth(); ++x)
{
bmp.setPixel(x, y, ((bmp.getPixel(x, y) & 0xFFFFFF) | newPixelAlpha));
}
}
Then this is the method I use to draw each bitmap to the canvas
public void drawSelf(Canvas canvas, Paint paint)
{
if(active) {
if (!selected) {
//paint.setAlpha(opacity);
canvas.drawBitmap(bitmap, rect.left, rect.top, null);
//This bit here is just if someone long-presses on the image, it gets "highlighted" but a rectangle over it, with transparency 170.
//Not being used at this point
} else {
paint.setAlpha(170);
canvas.drawRect(rect, paint);
canvas.drawBitmap(bitmap, rect.left, rect.top, paint);
}
}
}
The following is a screenshot of one image atop another, with no transparency (unfortunately, I need 10 reputation to include it in this post)
Whereas here, I have edited the alpha value of each pixel of the top image using the loop above, yet it is still "opaque"
http://tinypic.com/r/2j2dras/8
Perhaps it is actually "seeing" the canvas background colour as what is behind the image, rather than the other image? This would explain why it only gets darker when I make it transparent. I'm assuming that somehow I need to make canvas do some sort of per-pixel blending or something of that nature? Unfortunately my knowledge in this area is still quite limited, so I am unsure of what to try/where to go to from here.
I'd really appreciate any guidance on this :)
Thanks!
0 comments:
Post a Comment