I am converting a picture from a base64 string into an HICON
that could work when registering a new class:
WNDCLASSEX wc{};
wc.hIcon = < here >;
I got the base64_decode()
function here: base64.cpp
#include <windows.h> // GDI includes.
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
std::string base64 = "......";
std::string decodedImage = base64_decode(base64);
DWORD imageSize = decodedImage.length();
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
LPVOID pImage = ::GlobalLock(hMem);
memcpy(pImage, decodedImage.c_str(), imageSize);
IStream* pStream = NULL;
::CreateStreamOnHGlobal(hMem, FALSE, &pStream);
Gdiplus::Image image(pStream);
int wd = image.GetWidth();
int hgt = image.GetHeight();
auto format = image.GetPixelFormat();
Bitmap* bmp = new Bitmap(wd, hgt, format);
auto gg = std::unique_ptr<Graphics>(Graphics::FromImage(bmp));
gg->Clear(Color::Transparent);
gg->DrawImage(image, 0, 0, wd, hgt);
...
I couldn't find a way to get the HICON
from the Image
, so I was trying to convert the Image
to Bitmap
.
I'm getting these two errors on the line gg->DrawImage(image, 0, 0, wd, hgt);
C2664 'Gdiplus::Status Gdiplus::Graphics::DrawImage(Gdiplus::Image *,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL)': cannot convert argument 1 from 'Gdiplus::Image' to 'Gdiplus::Image *'
E0304 no instance of overloaded function "Gdiplus::Graphics::DrawImage" matches the argument list
CodePudding user response:
cannot convert argument 1 from 'Gdiplus::Image' to 'Gdiplus::Image *'
DrawImage()
expects a pointer to an Image
object, but you are passing it the actual object instead.
Change this statement:
gg->DrawImage(image, 0, 0, wd, hgt);
To this instead:
gg->DrawImage(&image, 0, 0, wd, hgt); // <-- note the added '&' ...