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); }
  • 相关阅读:
    HTML--1标签表格
    HTML--4格式布局
    HTML--3css样式表
    快速制作网页的方法
    表单
    表单练习——邮箱注册
    斐波那契数列
    0125 多线程 继承Thread 练习
    Hash(哈希)
    [COI2007] [luogu P1823] Patrik 音乐会的等待 解题报告 (单调栈)
  • 原文地址:https://www.cnblogs.com/gakusei/p/3142009.html
Copyright © 2011-2022 走看看