07-08-2010 02:36 AM
Hi,
I am doing the blending on the two images. Blending should happen such a way that, if there is a source pixel other than white it should be drawn onto the destination without any blending. If there is white pixel in the source and there is a destination pixle which has some color other than white, destination pixel should not be disturbed.
Basically what i need is if there is some area of the source image with the white pixel, that should not overwrite the destination pixel. All other area should be like regular source copy.
I am looking for a specific rop constant for this operation.
orgGraphics.rop(Graphics.ROP2_DSa, x, y ,ropBmp.getWidth(), ropBmp.getHeight(), ropBmp,x, y);
works fine, but it also blends two colors even though the source is non white.
Solved! Go to Solution.
07-08-2010 03:09 AM
I also don't understand exactly what you want. From your description, I came up with this:
source non white, dest non white => source
source non white, dest white => source
source white. dest non white => dest
source white, dest white => ?
If the '?' should be dest (or white), then this seems more like a ROP_SRCMONOEXPAND_COPY using the non-white part of the source as the mask. It doesn't sound like a blend at all.
07-08-2010 06:04 AM
Your understanding of my problem is perfect. How to mention the non white part of the source as mask?
I just replaced my ROP call as given below, it is not working
orgGraphics.rop(Graphics.ROP_SRCMONOEXPAND_COPY, x, y ,ropBmp.getWidth(), ropBmp.getHeight(), ropBmp,x, y);
07-08-2010 06:36 AM - edited 07-08-2010 07:22 AM
My source & destination bitmaps are color bitmaps. After changing to the ROP constant u mentioned, i just got white everywhere.
I am looking for simillar implementation of the AlphaComposite.SRC_OVER set to graphics2d class in regular java
07-08-2010 11:30 AM
After a little sleep, I see now that using ROP_SRCMONOEXPAND_COPY was not my brightest suggestion. It uses a monochrome bitmap as a mask to draw the foreground color--kind of a stamp. Not at all what you want.
It seems to me that you want to draw the the source image as if it were fully transparent at its white pixels. I think the easiest way to do that is to create such an image from the source. Perhaps something like this (totally untested) will work:
int OPAQUE_WHITE = 0xffffffff;
int TRANSPARENT_WHITE = 0x00ffffff;
int w = src.getWidth();
int h = src.getHeight();
int [] pixels = new int[w * h];
src.getARGB(pixels, 0, w, 0, 0, w, h);
for (int i = 0; i < pixels.length; ++i) {
if (pixels[i] == OPAQUE_WHITE) pixels[i] = TRANSPARENT_WHITE;
}
Bitmap src2 = new Bitmap(Bitmap.ROWWISE_16BIT_COLOR, w, h);
src2.createAlpha(Bitmap.ALPHA_BITDEPTH_MONO);
src2.setARGB(pixels, 0, w, 0, 0, w, h);
Then simply use drawBitmap with src2 into/over dest. If I got the logic right, the white areas of src2 ought to not draw.
I don't know if creating a new image from src is going to cause a big performance hit. Perhaps you can cache src2 if the same src image is reused.
07-12-2010 04:24 AM
Sounds nice idea. Let me try it today. I will update you with the solution.
07-12-2010 05:32 AM
Thanks. It works ![]()
07-12-2010 05:40 AM - edited 07-12-2010 06:06 AM
Thanks.
07-12-2010 06:37 AM
Ted,
It was a valuable information you gave, please can you look into my other post
Thanks