Click here to Skip to main content
15,889,116 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Check Driver Pin
Gisle Vanem25-Sep-13 0:24
Gisle Vanem25-Sep-13 0:24 
Questionwhen its required explicit keyword in constructor Pin
ranjithkumar8124-Sep-13 1:00
ranjithkumar8124-Sep-13 1:00 
AnswerRe: when its required explicit keyword in constructor Pin
André Kraak24-Sep-13 2:16
André Kraak24-Sep-13 2:16 
QuestionConvert raw image data to PNG Pin
Don Guy23-Sep-13 12:39
Don Guy23-Sep-13 12:39 
AnswerRe: Convert raw image data to PNG Pin
Garth J Lancaster23-Sep-13 13:03
professionalGarth J Lancaster23-Sep-13 13:03 
AnswerRe: Convert raw image data to PNG Pin
Randor 23-Sep-13 15:00
professional Randor 23-Sep-13 15:00 
GeneralRe: Convert raw image data to PNG Pin
Don Guy23-Sep-13 15:19
Don Guy23-Sep-13 15:19 
GeneralRe: Convert raw image data to PNG Pin
Randor 23-Sep-13 18:07
professional Randor 23-Sep-13 18:07 
Hi,

Don Guy wrote:
Does Image Encoding can convert raw image date to PNG format?
No

I gave you a link to the Bitmap Class[^]. You should consider using one of these class constructors to generate your Bitmap object.

Bitmap.Bitmap(INT, INT, INT, PixelFormat, BYTE*) constructor[^]
Bitmap.Bitmap(const BITMAPINFO*, VOID*) constructor[^]

Don Guy wrote:
I know Image.Save() can save a BMP file in PNG or JPG format, but here the purpose is not convert and save into the hard drive. But i want the PNG formatted data, which can be later used for other purposes.

Great. Since you already know that you can call Image.Save[^] to save to disk. Then surely you would know that you can also save to an in-memory IStream[^]:

Image.Save(IStream*, const CLSID*, const EncoderParameters*) method[^]


Here is an example from one of my personal projects. In this project I am taking screenshots of websites via the Webkit backing store and converting them to PNG image thumbnails and serving them over HTTP. This example reads from a HBITMAP to a Bitmap object then saves as an encoded PNG image into an in-memory IStream.

C++
BYTE * WebKitWnd::GetPNGImageFromBackingStore(UINT& iLength)
{
	BYTE *pRet = nullptr;
	iLength = 0;

	CDC memDC;
	memDC.CreateCompatibleDC(NULL);

	DIBSECTION ds;
	BITMAPINFOHEADER &bmInfo = ds.dsBmih;
	if(NULL != m_hBacking && NULL != ::GetObject(m_hBacking, sizeof(ds), &ds))
	{
		Bitmap bmp(m_hBacking,NULL);
		Graphics g(&bmp);
		CLSID  encoderClsid;
		BYTE *png_buffer = nullptr;
		if(TRUE == GetEncoderClsid(L"image/png", &encoderClsid))
		{
			IStream *buffer;
			VERIFY_SUCCEEDED(::CreateStreamOnHGlobal(NULL, FALSE, &buffer));
			bmp.Save(buffer,&encoderClsid,NULL);
			STATSTG statstg;
			VERIFY_SUCCEEDED(buffer->Stat(&statstg, STATFLAG_DEFAULT));
			ULONG m_bmpBufferSize = (ULONG)statstg.cbSize.LowPart;
			BYTE *png_buffer = new(std::nothrow) BYTE[m_bmpBufferSize];
			if(png_buffer)
			{
				LARGE_INTEGER li = {0};
				buffer->Seek(li, STREAM_SEEK_SET, NULL);
				ULONG m_nRead;
				buffer->Read(png_buffer,m_bmpBufferSize, &m_nRead);
				pRet = png_buffer;
				iLength = m_bmpBufferSize;
				buffer->Release();
			}
		}
	}
	memDC.DeleteDC();
	return pRet;
}



Best Wishes,
-David Delaune
GeneralRe: Convert raw image data to PNG Pin
Don Guy24-Sep-13 5:22
Don Guy24-Sep-13 5:22 
GeneralRe: Convert raw image data to PNG Pin
Don Guy24-Sep-13 5:41
Don Guy24-Sep-13 5:41 
GeneralRe: Convert raw image data to PNG Pin
Don Guy24-Sep-13 6:04
Don Guy24-Sep-13 6:04 
SuggestionRe: Convert raw image data to PNG Pin
Randor 24-Sep-13 7:29
professional Randor 24-Sep-13 7:29 
GeneralRe: Convert raw image data to PNG Pin
Don Guy24-Sep-13 11:07
Don Guy24-Sep-13 11:07 
QuestionHow to check if popup a Modal Window? Pin
yu-jian23-Sep-13 6:12
yu-jian23-Sep-13 6:12 
AnswerRe: How to check if popup a Modal Window? Pin
«_Superman_»23-Sep-13 6:40
professional«_Superman_»23-Sep-13 6:40 
GeneralRe: How to check if popup a Modal Window? Pin
yu-jian23-Sep-13 7:42
yu-jian23-Sep-13 7:42 
AnswerRe: How to check if popup a Modal Window? Pin
pasztorpisti23-Sep-13 9:17
pasztorpisti23-Sep-13 9:17 
AnswerRe: How to check if popup a Modal Window? Pin
Randor 23-Sep-13 18:26
professional Randor 23-Sep-13 18:26 
QuestionCreateFile on HBITMAP Pin
Don Guy20-Sep-13 11:41
Don Guy20-Sep-13 11:41 
AnswerRe: CreateFile on HBITMAP Pin
Richard MacCutchan20-Sep-13 21:34
mveRichard MacCutchan20-Sep-13 21:34 
AnswerRe: CreateFile on HBITMAP Pin
«_Superman_»21-Sep-13 21:05
professional«_Superman_»21-Sep-13 21:05 
AnswerRe: CreateFile on HBITMAP Pin
Chris Losinger23-Sep-13 9:28
professionalChris Losinger23-Sep-13 9:28 
QuestionFont Color Pin
Richard Andrew x6420-Sep-13 5:59
professionalRichard Andrew x6420-Sep-13 5:59 
AnswerRe: Font Color Pin
Richard MacCutchan20-Sep-13 7:28
mveRichard MacCutchan20-Sep-13 7:28 
GeneralRe: Font Color Pin
Richard Andrew x6420-Sep-13 8:43
professionalRichard Andrew x6420-Sep-13 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.