Hello! All time used the code given in article RSDN
"Gdi + .Graphic of new generation"

https://rsdn.ru/?article/gdi/gdiplus1.xml

Bitmap* BitmapFromResource(HINSTANCE hInstance, LPCTSTR szResName, LPCTSTR szResType) { HRSRC hrsrc = FindResource(hInstance, szResName, szResType); if(!hrsrc) return 0; // "ненастоящий" HGLOBAL - см. описание LoadResource HGLOBAL hgTemp = LoadResource(hInstance, hrsrc); DWORD sz = SizeofResource(hInstance, hrsrc); void* ptrRes = LockResource(hgTemp); HGLOBAL hgRes = GlobalAlloc(GMEM_MOVEABLE, sz); if(!hgRes) return 0; void* ptrMem = GlobalLock(hgRes); // Копируем растровые данные CopyMemory(ptrMem, ptrRes, sz); GlobalUnlock(hgRes); IStream *pStream; // TRUE означает освободить память при последнем Release HRESULT hr = CreateStreamOnHGlobal(hgRes, TRUE, &pStream); if(FAILED(hr)) { GlobalFree(hgRes); return 0; } // Используем загрузку из IStream Bitmap *image = Bitmap::FromStream(pStream); pStream->Release(); return image; } 

I draw in a standard

  Graphics g(hdc); g.DrawImage(BitmapFromResource(hInstance,MAKEINTRESOURCE(101),"PNG"),500,500) 

The problem is performance. The images of Rus are not allowed slowly (small ones are still normal, but a 600 by 200 picture, for example, will be drawn for a second (plus or minus :))). Can someone know a more productive version of drawing PNG from resources, without using third-party libraries . I will be grateful.

Updated

I changed the function a bit. I added a two-dimensional static array where I saved the module, the name and the Bitmap* itself Bitmap* . First, there is a check: if the name and the module are the same, then we return the Bitmap* that was previously Bitmap* , and that's it. If not, we do what we wrote on the RSDN, add the data to the array.

As it turned out, it was not a matter of finding (after all, we now only find it once), but in the method itself of the Graphics::DrawImage . Still, this method draws slowly

How to be?

  • It takes a long time to load, not the drawing itself. - Alexander Petrov
  • @AlexanderPetrov, I understand, and how to speed up? Can there be alternative methods? - Arthur Klochko
  • Look in nete png source decompressors. If you don’t find a good one, you can try to find the zip-deflate algorithm, correct what the halfman table would be in one piece in memory or find it with pools. There are open algorithms - they can be fixed. - nick_n_a
  • @nick_n_a Hmm, read, thank you - Arthur Klochko
  • Each time g.DrawImage(BitmapFromResource(hInstance,MAKEINTRESOURCE(101),"PNG"),500,500) new bitmap is loaded from the resources and immediately leaks. Call the BitmapFromResource only once and use the return value for all subsequent drawing calls, and at the end do not forget to delete it. - VTT

0