Click here to Skip to main content
15,917,328 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Clarification regarding the function CAsyncSocket::GetPeerName() Pin
manoharbalu25-Sep-13 0:48
manoharbalu25-Sep-13 0:48 
Questionset the version Pin
koll Zhu24-Sep-13 23:29
koll Zhu24-Sep-13 23:29 
AnswerRe: set the version Pin
Richard MacCutchan25-Sep-13 0:23
mveRichard MacCutchan25-Sep-13 0:23 
GeneralRe: set the version Pin
koll Zhu25-Sep-13 0:46
koll Zhu25-Sep-13 0:46 
GeneralRe: set the version Pin
koll Zhu25-Sep-13 0:51
koll Zhu25-Sep-13 0:51 
QuestionRe: set the version Pin
Maximilien25-Sep-13 8:03
Maximilien25-Sep-13 8:03 
AnswerRe: set the version Pin
koll Zhu25-Sep-13 16:06
koll Zhu25-Sep-13 16:06 
Questiondoes listivew_???? make handles leak...? Pin
JoneLe8624-Sep-13 19:10
JoneLe8624-Sep-13 19:10 
QuestionMFC PreTranslateMessage walks opposite the documentation. Pin
Vaclav_24-Sep-13 9:04
Vaclav_24-Sep-13 9:04 
AnswerRe: MFC PreTranslateMessage walks opposite the documentation. Pin
Randor 24-Sep-13 11:03
professional Randor 24-Sep-13 11:03 
QuestionHow to get Ip Address and Port No MFC Sockets Pin
manoharbalu24-Sep-13 3:26
manoharbalu24-Sep-13 3:26 
AnswerRe: How to get Ip Address and Port No MFC Sockets Pin
jeron124-Sep-13 3:40
jeron124-Sep-13 3:40 
QuestionCheck Driver Pin
john563224-Sep-13 1:25
john563224-Sep-13 1:25 
QuestionRe: Check Driver Pin
David Crow24-Sep-13 3:21
David Crow24-Sep-13 3:21 
AnswerRe: Check Driver Pin
jeron124-Sep-13 3:29
jeron124-Sep-13 3:29 
AnswerRe: Check Driver Pin
Erudite_Eric24-Sep-13 8:43
Erudite_Eric24-Sep-13 8:43 
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 

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.