in Education by
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)

1 Answer

0 votes
by
I've settled on avoiding this call now, and just copying the raw bitmap data over. The code: var writable = new WriteableBitmap(bmp.Width, bmp.Height, bmp.HorizontalResolution, bmp.VerticalResolution, PixelFormats.Bgra32, null); var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); writable.WritePixels(new Int32Rect(0, 0, bmp.Width, bmp.Height), data.Scan0, data.Stride * bmp.Height, data.Stride); GC.KeepAlive(bmp); context.DrawImage(writable, new Rect(0, 0, 80, 24)); (this might need a using or two) Also, if the writable bitmap is used directly as a source for something like Image then a call to Freeze helps prevent flicker on update, though I don't see why it would be necessary.

Related questions

0 votes
    I want to save an image from my WPF user control. It works but I got black bars on the right ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I want to save an image from my WPF user control. It works but I got black bars on the right ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I want to save an image from my WPF user control. It works but I got black bars on the right ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    My application has many views and I am using an AutoLogoffHelper class which maintains the timer for the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Given my animation scene1. How can I pause it using a button named “Skip” using C# code behind, and play another animation scene2 after....
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    I am developing Outlook add-ins which populates all the available shared mailboxes in to combo box and sends ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am developing Outlook add-ins which populates all the available shared mailboxes in to combo box and sends ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am having the code like In which I will bind the value for checkbox dynamically from db at buttonclick ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I am having the code like In which I will bind the value for checkbox dynamically from db at buttonclick ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    How may α − α and β − β particles will be emitted when . 90 T h 232 . changes into . 82 P b 208 . ? Select the correct answer from above options...
asked Jan 2, 2022 in Education by JackTerrance
0 votes
    Give one example each of ( a ) α − ( emission, ( b ) β c − − ( emission, and ( c ) K − ... Write an equation for these nuclear changes. Select the correct answer from above options...
asked Jan 2, 2022 in Education by JackTerrance
0 votes
    Write the nuclear reactions for the following radioactive decay: (a) . 92 U 238 . undergoes α − α decay. (b) . 91 ... B η + B decay. Select the correct answer from above options...
asked Jan 2, 2022 in Education by JackTerrance
0 votes
    Complete the following nuclear changes. (a) . 96 42 M o ( . . , n ) . 97 43 T c . (b) . . ( α , 2 n ) . ... 235 U ( α , β − ) . . . Select the correct answer from above options...
asked Jan 2, 2022 in Education by JackTerrance
0 votes
    If A and B are two independent events such that P( ˉ A )= 7 10 ,P( ˉ B )=α andP(A∪B)= 8 10 , then α, is ... 5/7 C. 1 D. none of these Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    Of the three independent event E1,E2 and E3 , the probability that only E1 occurs is α , only E2 occurs is β and only ... 2 C. 6 D. 4 Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
...