繁体   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