如何使用Linux C ++将位图转换为字节数组

时间:2013-06-19 10:54:07

标签: c++ linux

我正在开发一个应用程序,它将使用gtk_file_chooser_dialog_new打开一个图像,获取像素并将其转换为字节数组。转换后的数据将显示在阅读器的LCD上。我正在使用Linux C ++(GTK)。我找到了几个关于GDK_Pixbuf的文档。我尝试了那些我认为给我需要的数据但没有运气的功能。这是我找到的GDK-pixbuf。任何帮助,将不胜感激。

顺便说一句,我在C ++(windows)中有这些代码

iWidth = picRect.right - picRect.left;         iHeight = picRect.bottom - picRect.top;

    BitBlt(picHDC,0,0,(picRect.right - picRect.left),(picRect.bottom - picRect.top),hDC,0,0,SRCCOPY); 

    int iGraphicsDataCounter = 0;


    COLORREF rgb = ::GetPixel (picHDC, 0, 0);

    UINT uRed = GetRValue (rgb);
    int iSequenceIndex = 0;
    int iCounter = 0;
    byte aSequence[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };

            for(int iRowIndex = 0; iRowIndex < iHeight; iRowIndex++)
    {
        for(int iColumnIndex = 0; iColumnIndex < iWidth; iColumnIndex++)
        {
            rgb = ::GetPixel (picHDC, iColumnIndex, iRowIndex);
            uRed = GetRValue (rgb);
            if(uRed == 255)
                aGraphicsData[iCounter] |= 0x00;
            else
                aGraphicsData[iCounter] |= aSequence[iSequenceIndex];

            if(++iSequenceIndex == 8)
            {
                iCounter++;
                iSequenceIndex = 0;
            }
        }
    }

0 个答案:

没有答案