zoukankan      html  css  js  c++  java
  • 从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); }
  • 相关阅读:
    复利计算4.0单元测试(c语言)
    操作系统之“实验一”
    操作系统cmd算法
    <构建之法>之第一二三章的感悟
    assertion的语法和语义
    java对象的内存分配
    Oracle Berkeley DB Java 版
    acid数据库事务正确执行的四个基本要素的缩写编辑本义项
    volatile-java关键字
    Heritrix源码分析(十五)
  • 原文地址:https://www.cnblogs.com/gakusei/p/3142009.html
Copyright © 2011-2022 走看看