我看了截图都是先保存成位图bitmap,然后再处理,这样,占的空间其实已经大了,于是问一下:现在有没有直接不用通过压缩转换就可以得到jpg格式的图片呢??谢谢

解决方案 »

  1.   

    在内存中将位图转换为jpg再保存。
      

  2.   

    cximage中怎么截图放到内存中?
      

  3.   

    我对这个研究的时间不长,只说说我的想法!
    截完了就在内存中吧!
    HBITMAP hbitmap = CreateCompableBitmap (...)
    想对它操作,对hbitmap操作就行了.
    至于怎么改成jpg我还没有做过!
      

  4.   

    无论磁盘上的bmp文件是多大,你需要知道的是,这个文件需要在内存中至少这么大的地方,然后再通过各种压缩算法转换成jpg,即使你有什么工具可以直接将jpg文件直接读取并显示出来,你还需要清楚,这个jpg文件可能在你磁盘上就100k,可是在内存中还是转换成位图的,也就是说还是要很大的内存。至于直接保存成jpg的截图工具,我给你介绍一个:HyperSnap-DX 5
      

  5.   

    用gdi+抓屏并存成.jpg文件#include  <windows.h>  
    #include  <gdiplus.h>  
    #include  <stdio.h>  
     
    using  namespace  Gdiplus;  
     
    #pragma  comment  (lib,  "gdiplus.lib")  
     
    GdiplusStartupInput  gdiplusStartupInput;  
    ULONG_PTR                      gdiplusToken;  
     
    int  GetEncoderClsid(LPCWSTR  format,  CLSID*  pClsid)  
    {  
           UINT    num  =  0;  
           UINT    size  =  0;  
     
           ImageCodecInfo*  pImageCodecInfo  =  NULL;  
     
           GetImageEncodersSize(&num,  &size);  
           if(size  ==  0)  
                   return  -1;  
     
           pImageCodecInfo  =  (ImageCodecInfo*)(malloc(size));  
           if(pImageCodecInfo  ==  NULL)  
                   return  -1;  
     
           GetImageEncoders(num,  size,  pImageCodecInfo);  
     
           for(UINT  j  =  0;  j  <  num;  ++j)  
           {  
                   if(  wcscmp(pImageCodecInfo[j].MimeType,  format)  ==  0  )  
                   {  
                           *pClsid  =  pImageCodecInfo[j].Clsid;  
                           free(pImageCodecInfo);  
                           return  j;  
                   }  
           }  
     
           free(pImageCodecInfo);  
           return  -1;  
    }  
    //    参数  
    //            xs  =  图象x轴大小  
    //            ys  =  图象y轴大小  
    //            quality  =  jpeg图象质量  
     
    VOID        SaveCurScreenJpg(LPCWSTR  pszFileName,  int  xs,  int  ys,  int  quality)  
    {  
           HWND        hwnd  =  ::GetDesktopWindow();  
           HDC          hdc  =  GetWindowDC(NULL);  
           int          x  =  GetDeviceCaps(hdc,  HORZRES);  
           int          y  =  GetDeviceCaps(hdc,  VERTRES);  
           HBITMAP  hbmp  =  ::CreateCompatibleBitmap(hdc,  x,  y),  hold;  
           HDC          hmemdc  =  ::CreateCompatibleDC(hdc);  
           hold        =  (HBITMAP)::SelectObject(hmemdc,  hbmp);  
           BitBlt(hmemdc,  0,  0,  x,  y,  hdc,  0,  0,  SRCCOPY);  
           SelectObject(hmemdc,  hold);  
           {  
                   Bitmap    bit(xs,  ys),  bit2(hbmp,  NULL);  
                   Graphics        g(&bit);  
                   g.ScaleTransform((float)xs/x,  (float)ys/y);  
                   g.DrawImage(&bit2,  0,  0);  
     
                   CLSID                          encoderClsid;  
                   EncoderParameters  encoderParameters;  
     
                   encoderParameters.Count  =  1;  
                   encoderParameters.Parameter[0].Guid  =  EncoderQuality;  
                   encoderParameters.Parameter[0].Type  =  EncoderParameterValueTypeLong;  
                   encoderParameters.Parameter[0].NumberOfValues  =  1;  
                   encoderParameters.Parameter[0].Value  =  &quality;  
     
                   GetEncoderClsid(L"image/jpeg",  &encoderClsid);  
                   bit.Save(pszFileName,  &encoderClsid,  &encoderParameters);  
           }  
           ::DeleteObject(hbmp);  
           ::DeleteObject(hmemdc);  
           return;  
    }  
    int  APIENTRY  WinMain(HINSTANCE  hInstance,  
                                             HINSTANCE  hPrevInstance,  
                                             LPSTR          lpCmdLine,  
                                             int              nCmdShow)  
    {  
           GdiplusStartup(&gdiplusToken,  &gdiplusStartupInput,  NULL);  
           ::SaveCurScreenJpg(L".\\cap.400.300.30.jpg",  400,  300,  30);  
           ::SaveCurScreenJpg(L".\\cap.800.600.100.jpg",  800,  600,  100);  
           ::SaveCurScreenJpg(L".\\cap.800.600.100.jpg",  640,  480,  50);  
           GdiplusShutdown(gdiplusToken);  
     
           return  0;  
    }  
      

  6.   

    楼下仁兄的代码产生的JPG图片好小,比我原来的截的占空间缩小了很多,在些表示拜谢!!
      

  7.   

    说错了,是楼上,嘿嘿;
    不错楼上用的是GDI+,2000下不兼容