本文整理汇总了C++中gdiplus::Bitmap::Save方法的典型用法代码示例。如果您正苦于以下问题:C++ Bitmap::Save方法的具体用法?C++ Bitmap::Save怎么用?C++ Bitmap::Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gdiplus::Bitmap
的用法示例。
在下文中一共展示了Bitmap::Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertToJPEG
///Convert the given RGB array to a JPEG image. The JPEG image is returned in a BYTE array while the length of the array is returned through parameter
BYTE* convertToJPEG(BYTE* RGBArray, UINT &length) {
BITMAPINFO bmi; //Create bitmap header
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = 1920;
bmi.bmiHeader.biHeight = -1080;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 24;
Gdiplus::Bitmap* myImage = new Gdiplus::Bitmap(&bmi, RGBArray); //Form bitmap out of provided RGB array
IStream *jpgStream;
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid); //Get the encoder
CreateStreamOnHGlobal(NULL, TRUE, &jpgStream); //Get direct access to physical memory. Create a stream to save directly into it. Delete when stream is released
myImage->Save(jpgStream, &jpgClsid); //Save the jpg image into physical memory
STATSTG stats;
jpgStream->Stat(&stats, STATFLAG_NONAME); //Get stats of the jpg image; more importantly, the size
BYTE *jpg = new BYTE[stats.cbSize.QuadPart]; //Create byte array for transferring image to.
ULONG read;
LARGE_INTEGER lg;
lg.QuadPart = 0;
jpgStream->Seek(lg, STREAM_SEEK_SET, NULL); //Move to beginning of stream
jpgStream->Read(jpg, stats.cbSize.QuadPart, &read); //Read entire stream into the array
jpgStream->Release(); //Release the stream
length = stats.cbSize.QuadPart; //Save the length of the byte array
return jpg;
}
示例2: Export
void TVizMapContext::Export(const TStr& FNm, const TStr& EncoderType, const int& Width,
const int& Height, const bool& ShowPointNmP, const int& PointFontSize,
const int& PointNmFontScale, const double& PointWgtThreshold, const bool& ShowCatNmP,
const bool& ShowKeyWdP, const int& KeyWdFontSize, const bool& ShowMgGlassP,
const int& LegendGridWidth, const int& LegendGridHeight) {
// create graphics
Gdiplus::Bitmap* Bmp = new Gdiplus::Bitmap(Width, Height);
Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(Bmp);
PGks BmpGks = TWfGks::New();
// paint graphics
HDC HdcHandle = g->GetHDC(); BmpGks->BeginPaint(HdcHandle);
Paint(BmpGks, ShowPointNmP, PointFontSize, PointNmFontScale,
PointWgtThreshold, -1, ShowCatNmP, ShowKeyWdP, KeyWdFontSize, ShowMgGlassP,
LegendGridWidth, LegendGridHeight);
BmpGks->EndPaint(); g->ReleaseHDC(HdcHandle);
// save to disk
WCHAR* FNmWChar = new WCHAR[FNm.Len() + 1];
const int Res = MultiByteToWideChar(CP_ACP, 0,
FNm.CStr(), FNm.Len() + 1, FNmWChar, FNm.Len() + 1);
CLSID pngClsid; GetEncoderClsid(EncoderType, &pngClsid);
Bmp->Save(FNmWChar, &pngClsid, NULL);
// clean after
delete FNmWChar; delete Bmp; delete g;
}
示例3: GDIPlusDecoder
static void GDIPlusDecoder(CStdValVector* data) {
HGLOBAL hMem = ::GlobalAlloc(GMEM_FIXED, data->m_data->getLength());
BYTE* pMem = (BYTE*)::GlobalLock(hMem);
memcpy(pMem, data->m_data->getMemoryBase(), data->m_data->getLength());
IStream* pIStream = 0;
::CreateStreamOnHGlobal(hMem, FALSE, &pIStream);
Gdiplus::Bitmap* pImgBitmap = Gdiplus::Bitmap::FromStream(pIStream);
InitClsids();
pIStream->Release();
HRESULT hr = ::CreateStreamOnHGlobal(NULL, true, &pIStream);
pImgBitmap->Save(pIStream, &s_bmpClsid, NULL);
LARGE_INTEGER liTemp = {0};
pIStream->Seek(liTemp, STREAM_SEEK_SET, NULL);
STATSTG stats = {0};
pIStream->Stat(&stats, 0);
DWORD dwSize = (DWORD)stats.cbSize.QuadPart;
delete data->m_data;
data->m_data = new SkMemoryStream(dwSize);
pIStream->Read((void *)data->m_data->getMemoryBase(), dwSize, NULL);
::GlobalUnlock(hMem);
::GlobalFree(hMem);
pIStream->Release();
delete pImgBitmap;
}
示例4: SaveGIF
void SaveGIF(HBITMAP hBmp, TCHAR* szFilename) {
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) );
if( pBitmap ) {
// Get the CLSID of the GIF encoder.
CLSID clsidEncoder;
if( GetEncoderClsid(L"image/gif", clsidEncoder)) {
LPWSTR pswFile = mir_t2u(szFilename);
pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL);
mir_free(pswFile);
}
delete pBitmap;
}
Gdiplus::GdiplusShutdown(gdiplusToken);
}
示例5: SaveTIF
void SaveTIF(HBITMAP hBmp, TCHAR* szFilename)
{
//http://www.codeproject.com/Messages/1406708/How-to-reduce-the-size-of-an-Image-using-GDIplus.aspx
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::Status stat;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE));
if (pBitmap) {
// Get the CLSID of the GIF encoder.
CLSID EncCLSID;
if (GetEncoderClsid(L"image/tiff", EncCLSID)) {
//--- Create a 2-parameter array, for Compression and for Color Bit depth
Gdiplus::EncoderParameters* EncParams = (Gdiplus::EncoderParameters*) malloc(sizeof(Gdiplus::EncoderParameters) + 1 * sizeof(Gdiplus::EncoderParameter));
// Gdiplus::EncoderParameters pEncoderParameters;
//--- Use LZW Compression instead of Group 4, since it works for color and G4 doesn't
ULONG ulCompression = Gdiplus::EncoderValueCompressionLZW;
ULONG ulColorDepth = 24L;
EncParams->Count = 2;
EncParams->Parameter[0].Guid = Gdiplus::EncoderCompression;
EncParams->Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
EncParams->Parameter[0].NumberOfValues = 1;
EncParams->Parameter[0].Value = &ulCompression;
EncParams->Parameter[1].Guid = Gdiplus::EncoderColorDepth;
EncParams->Parameter[1].Type = Gdiplus::EncoderParameterValueTypeLong;
EncParams->Parameter[1].NumberOfValues = 1;
EncParams->Parameter[1].Value = &ulColorDepth;
LPWSTR pswFile = mir_t2u(szFilename);
stat = pBitmap->Save((const WCHAR*)pswFile, &EncCLSID, EncParams);
mir_free(pswFile);
free(EncParams);
}
delete pBitmap;
}
Gdiplus::GdiplusShutdown(gdiplusToken);
}
示例6: SaveBitmap
void GdiPlusAccess::SaveBitmap(Gdiplus::Bitmap &bmp, const Core::String &fileName, const GUID &format) {
CLSID encoder;
GetEncoderCLSID(format, encoder);
AssertGDIPlusSuccess(bmp.Save(*fileName, &encoder, nullptr), "cannot save bitmap");
}