BitmapSource equivalent in C++?

315 Views Asked by At

I have a working code written in C#, which takes an array of byte, representing a bitmap image, and encode it in base64, so it can be shown with a browser.

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);

It works fine but I need to make the same thing in C++. I have my byte array, which contains the same thing as the byte array in C#. The problem is that the BitmapSource compresses the bitmap and I dont understand how, from 10 Mo to 1.5 Mo for some bitmaps. How it is done ?

Actually, I can manage to encode my c++ bitmap buffer to base64, but it is too huge to be displayed on a browser.

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

I found BitmapSource was using "CachedBitmap", but I cannot figure out how it is calculated ...

1

There are 1 best solutions below

0
Autruche On

Solved my problem using 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());