diff options
author | George Hazan <george.hazan@gmail.com> | 2024-11-27 19:24:42 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-11-27 19:24:42 +0300 |
commit | 80e5db5c24521f325c0b7cd4619631e1853566b0 (patch) | |
tree | 2452cc742775b11d7238b7a7130af21de4085125 /plugins/NewStory/src/utils.cpp | |
parent | 0a2bac03e5bae0e72f02dbb1c6c56b8ab3822024 (diff) |
fiexs #4796 (NewStory: не отображается прозрачность у смайлов)
Diffstat (limited to 'plugins/NewStory/src/utils.cpp')
-rw-r--r-- | plugins/NewStory/src/utils.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index 811eac0e0d..f6aca92604 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -20,14 +20,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <msapi/comptr.h>
-FIBITMAP* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType)
+Bitmap* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType)
{
if (HRSRC hrsrc = FindResourceW(hInst, MAKEINTRESOURCE(resourceId), pwszType)) {
- if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) {
- auto *pMemory = FreeImage_OpenMemory((uint8_t*)LockResource(hRes), SizeofResource(hInst, hrsrc));
- auto *pDib = FreeImage_LoadFromMemory(FIF_PNG, pMemory);
- FreeImage_CloseMemory(pMemory);
- return pDib;
+ if (DWORD dwSize = SizeofResource(hInst, hrsrc)) {
+ if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) {
+ void *pImage = LockResource(hRes);
+
+ if (HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize)) {
+ void *pBuffer = ::GlobalLock(hGlobal);
+ if (pBuffer) {
+ memcpy(pBuffer, pImage, dwSize);
+
+ CComPtr<IStream> pStream;
+ HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
+ if (SUCCEEDED(hr))
+ return new Gdiplus::Bitmap(pStream);
+ }
+
+ GlobalFree(hGlobal); // free memory only if the function fails
+ }
+ }
}
}
|