相当于C ++中的BitmapSource?

时间:2019-03-12 15:17:30

标签: c# c++ bitmap base64 bitmapsource

我有一个用C#编写的工作代码,该代码需要一个代表位图图像的字节数组,并使用base64对其进行编码,因此可以在浏览器中显示。

byte[] bitmap = {...} //getting it from c++ .dll
BitmapSource bs = BitmapSource.Create(w, h, 96, 96, PixelFormats.Bgra32, null, bitmap, Bitmap_Raw_Stride);
return Convert.ToBase64String(bs);

它工作正常,但我需要在C ++中做同样的事情。我有字节数组,其中包含与C#中的字节数组相同的内容。 问题是BitmapSource会压缩位图,而我不明白如何将某些位图从10 Mo压缩到1.5Mo。如何完成?

实际上,我可以设法将c ++位图缓冲区编码为base64,但是它太大了,无法在浏览器中显示。

tring res = base64_encode(buffer, raw_stride* h); //buffer contains my bitmap

我发现BitmapSource使用的是“ CachedBitmap”,但我无法弄清楚它的计算方式...

1 个答案:

答案 0 :(得分:0)

使用LodePNG解决了我的问题。

byte* buffer = { ... }
string res;
std::vector<unsigned char> png;
unsigned error = lodepng::encode(png, buffer, w, h);
res = base64_encode(&png[0], png.size());