NativeImage vs HBitmap

Feb 19, 2013 at 7:46 PM

I also have a different question, maybe you can help.

The reason I found your CodePlex project was that I was having problems getting the code working with C#, I just couldn't get it running! If I recall correctly I kept getting a "violation" error, which didn't make sense to me untill I read your code. The problem was that you used the private property "nativeImage", where I was using the getHBitmap() method.

Did you found any information on what the difference is?

I am one of the coders of Greenshot, I wanted to speed up our obfuscate element in the editor.

Best wishes,
Feb 19, 2013 at 9:15 PM
Edited Feb 19, 2013 at 9:20 PM
From memory, get HBitmap creates a new GDI bitmap handle where as the native handle is the GDI+ handle to the image, which is basically a memory pointer to the object, these are two very different things, using reflection is the only way to get access to this handle, either that or create your image from scratch using flat GDI+ API calls, the same way the image class does in. Net.

Hope this helps :)

PS: Check out my legacy code blur functions in CSharpGDI plus project, it uses unsafe code but I spent a lot of time optimising it. It even supports multiple threads so is probably the fastest way to blur on the CPU. Of course, the GDI+ uses the graphics card so it will be faster.
Feb 19, 2013 at 10:06 PM
Aha, so it's just the GDi/GDI+ difference, this would explain why it confused me.

I will have a look at your legacy code maybe it will learn me a trick or two!
But I'm not unsatisfied with my current implementation. The box-blur makes a good approximation of the gaussian, if applied multiple times, and still is a lot faster.

I should actualy concentrate more on removing some badly grown logic, which makes it hard to optimise the way we redraw the screen in our editor.
Or even better, skip to WPF where there is no need to use GDi(+) to make the drawing perform properly, as it's really fast already!

Microsoft makes it harder to keep with the old stuff anyway, bitblt is not performing good on DWM enabled systems anymore.