【问题标题】:Base64 Image from encoding to displayBase64 图像从编码到显示
【发布时间】:2013-06-12 10:32:22
【问题描述】:

我正在尝试在通过插件从 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

但它不起作用!

我比较了我得到的字符串和我的代码,以及我用在线编码器得到的,不同的是,我的很短。

我做错了什么?标题问题?我不知道如何编码我的图像的标题?

【问题讨论】:

    标签: javascript image visual-c++ base64 encode


    【解决方案1】:

    您以错误的方式计算了图像大小。请尝试:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2013-11-17
      • 2015-03-07
      • 2013-04-16
      • 2023-01-16
      • 2015-06-17
      相关资源
      最近更新 更多