short note on GetBitmapHandle

grass In our Html Snapshot, there is a method GetBitmapHandle, which is to return an in-memory bitmap after a successful SnapUrl call. This method is useful when user wants to add some post processing to the image converted from html. For example, you may want to add your customer watermark text or image onto the html image or you want to clip out selected region of the image.

Here is the definition of the method.

HBITMAP GetBitmapHandle().

You can see the return value of it is a windows bitmap handle. Experienced programmers would ask a question: who will release the handle? Yes, the design here is that the caller MUST release the handle with a Win32 API call DeleteObject. If not, the handle will be leaked,whichwill lead to out of memory problem if there are lots of repeated call.

If you are using .Net programming languages such as C# or VB.Net, you have to use the interop service provided by .Net platform. The DeleteObject API can be imported into C# as follows.

        [DllImport("gdi32.dll")]
        public static extern bool DeleteObject(
            IntPtr handle
            );

Then it can be used just like a normal C# static method. There is a working demo in DemoC#GetAPage in the trial package of html snapshot.