Jump to content
Bilgus

Gdi+ Cached Bitmap Functions

Recommended Posts

Posted (edited)

I was looking through the gdiplus.dll and saw the cached bitmap functions

https://docs.microsoft.com/en-us/windows/win32/api/gdiplusheaders/nl-gdiplusheaders-cachedbitmap

Quote

A CachedBitmap object stores a bitmap in a format that is optimized for display on a particular device. To display a cached bitmap, call the Graphics::DrawCachedBitmap method.

Functions:

Spoiler
Func __GDIPlus_GraphicsDrawCachedBitmap($hGraphics, $hCachedBitmap, $iX, $iY)
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDrawCachedBitmap", "handle", $hGraphics, "handle", $hCachedBitmap, "int", $iX, "int", $iY)
    If @error Then Return SetError(@error, @extended, False)
    If $aResult[0] Then Return SetError(10, $aResult[0], False)

    Return True
EndFunc

Func __GDIPlus_CachedBitmapCreate($hGraphics, $hBitmap)
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipCreateCachedBitmap", "handle", $hBitmap, "handle", $hGraphics, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)

    Return $aResult[3]
EndFunc

Func __GDIPlus_CachedBitmapDispose($hCachedBitmap)
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDeleteCachedBitmap", "handle", $hCachedBitmap)
    If @error Then Return SetError(@error, @extended, False)
    If $aResult[0] Then Return SetError(10, $aResult[0], False)

    Return True
EndFunc

 

;Short example (pseudocode!)
Local $iW, $iH, $hWnd ;<- You supply these

Local $hG = _GDIPlus_GraphicsCreateFromHWND($hWnd)

Local $hBmp = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hG)

Local $hCachedBmp = __GDIPlus_CachedBitmapCreate($hG, $hBmp)

__GDIPlus_GraphicsDrawCachedBitmap($hG, $hCachedBmp, 0, 0) ;(hGraphics, hCachedBmp, X, Y)

__GDIPlus_CachedBitmapDispose($hCachedBmp)

 

Edited by Bilgus
!G

Share this post


Link to post
Share on other sites
Posted (edited)

Nice finding @Bilgus.  I just incorporated it in my Multiple GIF automation UDF, and it is working very good.  Very fast, although I need to make some more tests.  Thanks.

Edit : __GDIPlus_CachedBitmapDispose($hCachedBmp) always return False with error 3 (OutOfMemory).  The value of the handle is valid as it is draw correctly.  But in a GIF situation, there is a terrible memory leaks because it is unable to delete the object and after awhile, it makes the script crash.  Investigating...

Edited by Nine

Share this post


Link to post
Share on other sites

Found the problem...There is a typo in the API function name (capital G)...I misinterpreted the returning result, I first thought it was the function returning 3, but it was the dllcall that was returning @error 3...Now all works wonderfully.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...