Archived

This topic is now archived and is closed to further replies.

malpass

Comparing Transparent Bitmaps

Recommended Posts

morebeer    122
i''ve read your post 3 times, but couldn''t figure out exactly...

do you want to compare 2 rectangular areas of one or more image(s), taking the transparency (i.e. color-key or alpha values) into account? i.e. using one image as some sort of alpha-mask to see which pixels you want to copy into a new image, and which pixels to skip?

Share this post


Link to post
Share on other sites
malpass    122
ok, first I want to be able to read part of the screen into a bitmap (like a print screen, but just a section) called "screen".

Then, i have another bitmap of a picture called "pic", and thats transparent. I want to make "screen" transparent, but only in the parts that are transparent on "pic".

Then I want to compare them to check if there identical

Share this post


Link to post
Share on other sites
malpass    122
ok, start with the first question, how do I get color from a location of the screen, possibly a full section, not just pixel.

I tryed importing GetPixel() from C++ like this:

// Get pixel at point
[DllImport("gdi32.dll")]
public static extern int GetPixel(IntPtr hWnd, int x, int y);

that imports fine but I don''t know if the return value is right because that function when I use it in C# returns -1. I tryed telling it to return byte and Color but if I try Color it can''t import it, and if i try byte it returns 255 all the time.

Share this post


Link to post
Share on other sites
malpass    122
because there arent any to get screen pixels.

What if i call Print Screen (I can do that) then somehow import the bitmap from the clipboard, can anyone tell me how to do that?

Share this post


Link to post
Share on other sites
malpass    122
i''v managed to do a wierd thing that now gets me a screen cap, but now how can I make that transparent according to the transparency of another image, or just check the non-transparent bits of the other image with the same bits on the screen cap?

Share this post


Link to post
Share on other sites
Zipster    2365
Have your mask be a monochrome device context. Put the screen image into a color DC, and use BitBlt with the SRCAND raster op, and it should work. Transparent portions of the destination image should be black I imagine.

I haven''t tested it, but it sounds promising.

Share this post


Link to post
Share on other sites
malpass    122
ye, thats what I did. But then I need an efficient way to compare the bitmaps. Would I just say

if (myImage1.Equals(myImage2)) // whatever

would that work?

Share this post


Link to post
Share on other sites