簡體   English   中英

從編碼到顯示的Base64圖像

[英]Base64 Image from encoding to display

我試圖在通過插件從Visual C ++獲取的網頁上顯示圖像。

std::string DIBtoURI(LPBITMAPINFOHEADER lpbmih){


    int width = lpbmih->biWidth;

   int height = lpbmih->biHeight; // height < 0 if bitmap is top-down
   if (height < 0)
       height = -height;


   // Populate the pixels array.

   unsigned char *bitmap = (unsigned char *) lpbmih +
                           sizeof(BITMAPINFOHEADER);


   HBITMAP f = CreateBitmap(width,height,1,24,bitmap);
   BITMAP bit;
   GetObject(f, sizeof(BITMAP), &bit);




   // Allocate memory.
   BYTE* pBitmapData = new BYTE[ bit.bmWidth*bit.bmHeight ];
    ZeroMemory( pBitmapData, bit.bmWidth*bit.bmHeight );

    // Get bitmap data.
    GetBitmapBits(f, bit.bmWidth*bit.bmHeight, pBitmapData );


    std::string tee = base64_encode(pBitmapData,bit.bmWidth*bit.bmHeight);

   return tee;
}

在我的函數中,您可以看到我得到了一個BITMAPINFOHEADER(來自Twain),我從中創建了一個BITMAP,然后使用在google上找到的base64編碼器: http : //www.adp-gmbh.ch/cpp/ common / base64.html

我得到一個字符串給網頁,我正在嘗試做

var src="image/jpeg;base64," + string_from_cpp

但這是行不通的!

我將代碼中的字符串與在線編碼器中的字符串進行了比較,不同的是,我的字符串很短。

我究竟做錯了什么? 標頭問題? 我不知道如何編碼圖像的標題?

您以錯誤的方式計算了圖像尺寸。 請試試:

((((bit.bmWidth * 24)+ 31)/32)*4)*bit.bmHeight

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM