예제 #1
0
bool SaveImageEx(LPCWSTR asImgPath, HBITMAP hBitmap)
{
	if (!InitializeGdiPlus())
		return false;

	CLSID codecClsid = {};
	if (GetCodecClsid(L"image/png", &codecClsid) < 0)
		return false;

	bool lbRc = false;
	Gdiplus::Status lRc;
	GUID EncoderQuality = {0x1d5be4b5, 0xfa4a, 0x452d, {0x9c,0xdd,0x5d,0xb3,0x51,0x05,0xe7,0xeb}};

	Gdiplus::EncoderParameters encoderParameters;
	Gdiplus::GpImage *pImg = NULL;

	#ifdef _DEBUG
	DWORD nErrCode = 0;
	BITMAP bmpInfo = {};
	nErrCode = GetObject(hBitmap, sizeof(bmpInfo), &bmpInfo);
	#endif

	lRc = GdipCreateBitmapFromHBITMAP(hBitmap, NULL, &pImg);

	if ((lRc == Gdiplus::Ok) && pImg)
	{
		encoderParameters.Count = 1;
		encoderParameters.Parameter[0].Guid = EncoderQuality;
		encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
		encoderParameters.Parameter[0].NumberOfValues = 1;
		long quality = 75;
		encoderParameters.Parameter[0].Value = &quality;

		lRc = GdipSaveImageToFile(pImg, asImgPath, &codecClsid, &encoderParameters);

		if (lRc == Gdiplus::Ok)
			lbRc = true;

		GdipDisposeImage(pImg);
	}
	else if (lRc == Gdiplus::Win32Error)
	{
		// Возможно, это проблемы с палитрой в WinXP
		#ifdef _DEBUG
		nErrCode = GetLastError();
		#endif
		_ASSERTE(lRc == Gdiplus::Ok);
	}
	else
	{
		_ASSERTE((lRc == Gdiplus::Ok) && pImg);
	}

	return lbRc;
}
예제 #2
0
파일: LoadImg.cpp 프로젝트: G-VAR/ConEmu
bool SaveImageEx(LPCWSTR asImgPath, LPBYTE pBmpData, DWORD cbBmpDataSize)
{
	if (!InitializeGdiPlus())
		return false;

	CLSID codecClsid = {};
	if (GetCodecClsid(L"image/png", &codecClsid) < 0)
		return false;

	bool lbRc = false;
	Gdiplus::Status lRc;
	MStream *pStream = new MStream();

	if (pStream)
	{
		pStream->SetData(pBmpData, cbBmpDataSize);
		GUID EncoderQuality = {0x1d5be4b5, 0xfa4a, 0x452d, {0x9c,0xdd,0x5d,0xb3,0x51,0x05,0xe7,0xeb}};

		Gdiplus::EncoderParameters encoderParameters;
		Gdiplus::GpImage *pImg = NULL;
		
		lRc = GdipLoadImageFromStream((IStream*)pStream, &pImg);

		if ((lRc == Gdiplus::Ok) && pImg)
		{
			encoderParameters.Count = 1;
			encoderParameters.Parameter[0].Guid = EncoderQuality;
			encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
			encoderParameters.Parameter[0].NumberOfValues = 1;
			long quality = 75;
			encoderParameters.Parameter[0].Value = &quality;

			lRc = GdipSaveImageToFile(pImg, asImgPath, &codecClsid, &encoderParameters);

			if (lRc == Gdiplus::Ok)
				lbRc = true;

			GdipDisposeImage(pImg);
		}

		pStream->Release(); pStream=NULL;
	}

	return lbRc;
}
예제 #3
0
파일: LoadImg.cpp 프로젝트: G-VAR/ConEmu
bool SaveImageEx(LPCWSTR asImgPath, HBITMAP hBitmap)
{
	if (!InitializeGdiPlus())
		return false;

	CLSID codecClsid = {};
	if (GetCodecClsid(L"image/png", &codecClsid) < 0)
		return false;

	bool lbRc = false;
	Gdiplus::Status lRc;
	GUID EncoderQuality = {0x1d5be4b5, 0xfa4a, 0x452d, {0x9c,0xdd,0x5d,0xb3,0x51,0x05,0xe7,0xeb}};

	Gdiplus::EncoderParameters encoderParameters;
	Gdiplus::GpImage *pImg = NULL;
	
	lRc = GdipCreateBitmapFromHBITMAP(hBitmap, NULL, &pImg);

	if ((lRc == Gdiplus::Ok) && pImg)
	{
		encoderParameters.Count = 1;
		encoderParameters.Parameter[0].Guid = EncoderQuality;
		encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
		encoderParameters.Parameter[0].NumberOfValues = 1;
		long quality = 75;
		encoderParameters.Parameter[0].Value = &quality;

		lRc = GdipSaveImageToFile(pImg, asImgPath, &codecClsid, &encoderParameters);

		if (lRc == Gdiplus::Ok)
			lbRc = true;

		GdipDisposeImage(pImg);
	}

	return lbRc;
}