VAPI(VanillaBinary) VanillaSaveImageToBinary(VanillaImage Image, VanillaImageFormat ImageFormat) { wchar_t* MineType; switch (ImageFormat) { case ImageFormatPNG: MineType = L"image/png"; break; case ImageFormatJPEG: MineType = L"image/jpeg"; break; default: MineType = NULL; break; } if (!MineType) { return false; } CLSID Clsid; GetImageCLSID(MineType, &Clsid); VANILLA_ICONV; IStream* Stream; CreateStreamOnHGlobal(NULL, true, &Stream); if (Image->Image->Save(Stream, &Clsid) != Gdiplus::Status::Ok) { return NULL; } HGLOBAL HGlobal; if (GetHGlobalFromStream(Stream, &HGlobal) != S_OK) { Stream->Release(); return NULL; } VanillaInt Length = GlobalSize(HGlobal); if (Length <= 0) { Stream->Release(); return NULL; } VanillaBinary Binary = new VBinary; Binary->Length = Length; Binary->Address = (VanillaByte*)malloc(Length); VanillaAny Address = GlobalLock(HGlobal); memcpy(Binary->Address, Address, Length); GlobalUnlock(HGlobal); Stream->Release(); return Binary; }
BOOL CCBitmapConvert::TranstToBMP(string srcPath,string destPath) { remove(destPath.c_str()); WCHAR wCH[255] = {0}; WCHAR wCH1[255] = {0}; wstring wstrPath = s2ws(srcPath); wcscpy(wCH,wstrPath.c_str()); Image img(wCH);//这里的图片可以是其它格式 CLSID pngClsid; GetImageCLSID(L"image/bmp", &pngClsid);//这里的图片可以是其它格式,此处转化为BMP格式 wstrPath = s2ws(destPath); wcscpy(wCH1, wstrPath.c_str()); img.Save(wCH1, &pngClsid, NULL); return TRUE; }
VAPI(VanillaBool) VanillaSaveImageToFile(VanillaImage Image, VanillaText FileName, VanillaImageFormat ImageFormat) { wchar_t* MineType; switch (ImageFormat) { case ImageFormatPNG: MineType = L"image/png"; break; case ImageFormatJPEG: MineType = L"image/jpeg"; break; default: MineType = NULL; break; } if (!MineType) { return false; } CLSID Clsid; GetImageCLSID(MineType, &Clsid); VANILLA_ICONV; return Image->Image->Save(VANILLA_U2W(FileName).c_str(), &Clsid) == Gdiplus::Status::Ok; }