

HBITMAP g_hBitmap = NULL //for displaying on window Int gRozXObrazu, gRozYObrazu //Size of picture X,Y Int gRozXOkna, gRozYOkna //size of working window You can resize it and it is much faster! Artur Czekalski / Polandīitmap *g_pGDIBitmap //for loading picture Use: GetHBITMAP(Gdiplus::Color(), &g_hBitmap) for HBITMAP and draw using my function ShowBitmapStretch(). Here it is.ĭont use: Graphics graphics(hdc) graphics.DrawImage(gpBitmap, 0, 0) It is slow. I had the same problem and I found the best solution.
#Drawit too speed draw coulusses code#
The same could have been used by the Internet Explorer team to draw images when the user is running high dpi (ie is very slow drawing zoomed images, because they use GDI+).įirst sorry for ma English, and the code is partly in polish, but it's simple to understand. I use the routine to draw glyphs on buttons, taking into account the current DPI. Int glyphSize = 16 * (GetCurrentDpi() / 96) ĭrawCachedBitmap(imgPrintInvoice, ref imgPrintInvoiceCached, graphics, You then pass it in subsequent calls, e.g.: Image imgPrintInvoice = new Image.FromFile("printer.png") ĬachedBitmap imgPrintInvoiceCached = null The first call to DrawCachedBitmap it cached version will be created. The cachedBitmap is passed in by reference. Graphics.DrawCachedBitmap(cachedBitmap, x, y) The API is telling us we have to recreate the cached bitmap If (graphics.DrawCachedBitmap(cachedBitmap, x, y) Ok) then Check if we need to create the "cached" version of the bitmapī := TGDIPlusHelper.ResizeImage(image, width, height) ĬachedBitmap := TGPCachedBitmap.Create(b, graphics) If (CachedBitmap.BitmapWidth width) or (CachedBitmap.BitmapHeight height) thenįreeAndNil(CachedBitmap) //nil'ing it will force it to be re-created down below Check if we have to invalidate the cached image because of size mismatch i've chosen to not throw exceptions during paint code - it gets very nasty Graphics: TGPGraphics x, y: Integer width, height: Integer)

In that case the DrawImage will fail, and you have to re-created the CachedBitmap: class procedure TGDIPlusHelper.DrawCachedBitmap(image: TGPImage This happens if the user changes resolutions or color depths (e.g. The caveat is that the CachedBitmap can become invalid - meaning it can't be used to draw. But in there end i have a function bit of (Delphi) code that does it. What i've learned on my own since last October is that you really want to draw a "cached" version of your bitmap.

GDI+ will perform scaling to get the image to come out the right "size" (i.e. The reason is because of dpi differences between the dpi of bitmap and the dpi of the destination. i had since found out, but guys comment reminded me of my old answer: you want to specify the destination size even though it matches the source size: DrawImage(bitmap, 0, 0, bitmap.GetWidth, bitmap.GetHeight) (i would hope it doesn't bother going through all 12 million pixels performing no actual work). Like i said, i doubt it will make any difference, because i'm sure that DrawImage checks the Width and Height of the bitmap, and if there's no resizing needed, just calls this overload. I don't think they'll make much of a different, but since you're not actually needing to resize the image, try using the overload of DrawImage that doesn't (attempt) to resize: DrawImage(bitmap,0,0) But now I need to draw Bitmap, and write some algorithm on Bitmap's bits array, how can I get BITMAPINFO if I have an Bitmap object? It's really annoying -_-| If I want to use StretchDIBits, I need to pass BITMAPINFO, But how can I get BITMAPINFO from a Gdi+ Bitmap Object? I did the experiment by FreeImage lib, I call StretchDIBits using FreeImageplus object, it draw really fast. , ,īYTE* dib, dibinfo, DIB_RGB_COLORS, SRCCOPY) StretchDIBits(hDC, rcDest.left, rcDest.top, This native GDI function also draws the image into the screen, and it just take 1 ms: SetStretchBltMode(hDC, COLORONCOLOR) How can I improve it? Or is any thing wrong? I cannot use CachedBitmap, because I want to edit the bitmap later. this part takes about 300ms, terrible! int width = bitmap->GetWidth() Bitmap *bitmap = Bitmap::FromFile("XXXX".) I am using a GDI+ Graphic to draw a 4000*3000 image to screen, but it is really slow.
