capturing a screen shot as png file (MFC - C++)

closed account (187f92yv)
hi,
does anyone know how to get a screen shot as a png file (under MFC, C++)

i am able to get screen shot as a HBITMAP. I have converted it to device independent bits (DIB) but i dont know how to convert these bits to png in memory.

I am aware i can use CImage to save the hbitmap as a png:
CImage image;
image.Attach(hBitmap);
image.Save("c:\\pngPicture.png");


but i really dont wanna do this as the png file will be sent over the network (thus saving it on disk will not be such good idea).

any ideas will be welcome,
thanks!
Last edited on
closed account (z05DSL3A)
Off the top of my head, there is a an overloaded CImage::Save that takes a stream, could you create a memory stream and save the CImage to that?
closed account (187f92yv)
thanks Grey Wolf.....that works!

yep, im creating a stream object using CreateStreamOnHGlobal() and then using the overloaded CImage::Save :D



IStream* pStream;
hres = CreateStreamOnHGlobal ( 0 , TRUE , &pStream );
hr = myImage.Save(pStream, Gdiplus::ImageFormatPNG);
Topic archived. No new replies allowed.