Gdiplus and Jpeg save
-
How can I save a window with graphical paints to a jpeg file???? See the code below: ///////////////////////////////////////////////////////////////////////////////// //gdiplus //////////////////////////////////////////////////////////////////////// int GetCodecClsid(const WCHAR* format, CLSID* pClsid){ UINT j,num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo * pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo *)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(j=0; jtexto,pDoc->texto.GetLength()); arquivo.Close(); CPaintDC dc(this); // device context for painting using namespace Gdiplus; Graphics graphics(dc.m_hDC); Pen blue (Color(255, 0, 0, 255)); Pen red (Color(255, 255, 0, 0)); int y = 256; for (int x = 0; x < 256; x += 5){ graphics.DrawLine(&blue, 0, y, x, 0); graphics.DrawLine(&red, 256, x, y, 256); y -= 5; } for (y = 0; y < 256; y++){ Pen pen(Color(y, 0, 255,0)); graphics.DrawLine(&pen, 0, y, 256, y); Sleep(20); } for (x = 0; x < 256; x++){ Pen pen(Color(x, 255, 0, 255)); graphics.DrawLine(&pen, x, 100, x, 200); Sleep(20); } // Write window ----> Image Im(L"fig.gif", FALSE); // :) CLSID GifCodec; GetCodecClsid(L"image/jpeg", &GifCodec); Im.Save(L"gif.jpg", &GifCodec, NULL); }
-
How can I save a window with graphical paints to a jpeg file???? See the code below: ///////////////////////////////////////////////////////////////////////////////// //gdiplus //////////////////////////////////////////////////////////////////////// int GetCodecClsid(const WCHAR* format, CLSID* pClsid){ UINT j,num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo * pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo *)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(j=0; jtexto,pDoc->texto.GetLength()); arquivo.Close(); CPaintDC dc(this); // device context for painting using namespace Gdiplus; Graphics graphics(dc.m_hDC); Pen blue (Color(255, 0, 0, 255)); Pen red (Color(255, 255, 0, 0)); int y = 256; for (int x = 0; x < 256; x += 5){ graphics.DrawLine(&blue, 0, y, x, 0); graphics.DrawLine(&red, 256, x, y, 256); y -= 5; } for (y = 0; y < 256; y++){ Pen pen(Color(y, 0, 255,0)); graphics.DrawLine(&pen, 0, y, 256, y); Sleep(20); } for (x = 0; x < 256; x++){ Pen pen(Color(x, 255, 0, 255)); graphics.DrawLine(&pen, x, 100, x, 200); Sleep(20); } // Write window ----> Image Im(L"fig.gif", FALSE); // :) CLSID GifCodec; GetCodecClsid(L"image/jpeg", &GifCodec); Im.Save(L"gif.jpg", &GifCodec, NULL); }
I use OpenIL for all my image reading and writing. OpenIL supports writing .jpgs and .gifs (and many other formats), though it really helps to be familiar with some OpenGL since OpenIL is sturctured very similarly. There are quite a few image libraries out there that can handle what you want, so you shouldn't have to reinvent the wheel.