I've created a semi-transparent test image, filled with 128-alpha black. I draw it while alternating between two methods: WPF native and GDI interop. They come out completely different; the WPF one is done correctly, but the GDI appears to be blended against white first, before being drawn:
If drawn against a photo, the GDI part lightens what's below it, even though a 0,0,0,128 color should darken whatever is below it:
The code goes like this:
if (iteration % 2 == 0)
context.DrawImage(new BitmapImage(new System.Uri("I:/test.png")),
new Rect(0, 0, 80, 24));
else
{
var bmp = (D.Bitmap) D.Bitmap.FromFile("I:/test.png");
var handle = bmp.GetHbitmap();
var bmpSource = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero,
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
context.DrawImage(bmpSource, new Rect(0, 0, 80, 24));
WinAPI.DeleteObject(handle);
GC.KeepAlive(bmp);
}
For the second image, I changed the Rect size for the WPF one to show that they don't overlap.
How do I draw a semi-transparent GDI image correctly?
(yes, it really has to be a GDI image for complex reasons - in reality it doesn't come from a file, but from some external code, but the problem is reproduceable easily with a file)
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)