• 从HDC转换到leptonica PIX


    void CAssistDlg::OnBnClickedTest()
    {
        HDC hdc = ::GetDC(NULL);
        HDC hdcMem = CreateCompatibleDC(hdc);
        HBITMAP hBmpMem = CreateCompatibleBitmap(hdc, 234, 234);
        HBITMAP hBmpOld = (HBITMAP)SelectObject(hdcMem, hBmpMem);
        BitBlt(hdcMem, 0, 0, 234, 234, hdc, 127, 518, SRCCOPY);
    
        {
            HDC hdcThis = GetDC()->GetSafeHdc();
            BitBlt(hdcThis, 0, 0, 234, 234, hdcMem, 0, 0, SRCCOPY);
            
            BITMAP bmp = {0};//BITMAPINFO;BITMAPINFOHEADER;
            int ret = ::GetObject(hBmpMem, sizeof(bmp), &bmp);
    
            BITMAPINFOHEADER bmi = {0};
            bmi.biSize = sizeof(bmi);
            bmi.biWidth = bmp.bmWidth;
            bmi.biHeight = -bmp.bmHeight;
            bmi.biPlanes = bmp.bmPlanes;
            bmi.biBitCount = bmp.bmBitsPixel;
            bmi.biSizeImage = bmp.bmWidth * bmp.bmHeight * bmp.bmBitsPixel / 8;
            bmi.biCompression = BI_RGB;
    
            BYTE *pBuf = new BYTE[bmi.biSizeImage];
            int ret2 = GetDIBits(hdcMem, hBmpMem, 0, bmp.bmHeight, pBuf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);    
    
            for (int i = 0;i < bmp.bmHeight;++i)
            {
                for (int j = 0;j < bmp.bmWidth;++j)
                {
                    BYTE r = pBuf[j * 4 + i * bmp.bmWidthBytes + 2];
                    BYTE g = pBuf[j * 4 + i * bmp.bmWidthBytes + 1];
                    BYTE b = pBuf[j * 4 + i * bmp.bmWidthBytes + 0];
                    
                    pBuf[j * 4 + i * bmp.bmWidthBytes + 3] = r; //r
                    pBuf[j * 4 + i * bmp.bmWidthBytes + 2] = g; //g
                    pBuf[j * 4 + i * bmp.bmWidthBytes + 1] = b; //b
                    pBuf[j * 4 + i * bmp.bmWidthBytes + 0] = 0xff; //a
                }
            }
    
            
            PIX pix = {0};
            pix.w = bmp.bmWidth;
            pix.h = bmp.bmHeight;
            pix.informat = IFF_BMP;
            pix.d = bmp.bmBitsPixel;
            pix.wpl = bmp.bmWidthBytes / 4;
            pix.data = (l_uint32 *)pBuf;
            pix.refcount = 1;
            pixWrite("D:\pix.bmp", &pix, IFF_BMP);

       delete []pBuf; } SelectObject(hdcMem,hBmpOld); DeleteDC(hdcMem); DeleteObject(hBmpMem); ::ReleaseDC(NULL, hdc); }
  • 相关阅读:
    背景透明的static控件
    MFC应用程序配置不正确解决方案
    #pragma once与 #ifndef的区别
    一种新颖的流程控制方式
    DbgView.exe的应用和使用类
    内存对齐的一点个人理解
    MFC下实现透明位图
    结束已知应用程序名的进程
    基本线程编程
    Linux下PCI设备驱动程序开发的经典文章
  • 原文地址:https://www.cnblogs.com/gakusei/p/3142009.html
Copyright © 2020-2023  润新知