你好,游客 登录 注册 搜索
背景:
阅读新闻

jpeg to bmp 内存图像转换 - Augusdi的专栏

[日期:2013-03-16] 来源:  作者: [字体: ]
不需要CxImage这样的第三方扩展库

微软的GDI+也可以转换的

CImage   mmage;   
    HWND   hWnd   =   ::GetDesktopWindow();//获得屏幕的HWND.   
    HDC   hScreenDC   =   ::GetDC(hWnd);       //获得屏幕的HDC.   
    HDC   MemDC   =   ::CreateCompatibleDC(hScreenDC);   
    RECT   rect;     
            
    ::GetWindowRect(hWnd,&rect);   
      
    HBITMAP   hBitmap   =   ::CreateCompatibleBitmap(hScreenDC,rect.right,rect.bottom);   
    HGDIOBJ   hOldBMP   =   ::SelectObject(MemDC,hBitmap);   
    ::BitBlt(MemDC,0,0,rect.right,rect.bottom,hScreenDC,rect.left,rect.top,SRCCOPY);   
    hBitmap=(HBITMAP)::SelectObject(MemDC,hOldBMP);   
      
    mmage.Attach(hBitmap);   
    IStream*   pStmImage   =   NULL;   
            
    HGLOBAL   hMemBmp   =   GlobalAlloc(GMEM_MOVEABLE,0);//可移动的缓冲区   
    if   (hMemBmp   ==   NULL)   return 0;   
    CreateStreamOnHGlobal(hMemBmp,   FALSE,   &pStmImage);//将内存区B作为流的起始   
    if   (pStmImage   ==   NULL)   
    {   
        GlobalFree(hMemBmp);   
        AfxMessageBox("为空");   
        return   0;   
     }   
    
    mmage.Save(pStmImage,Gdiplus::ImageFormatJPEG);  






收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻