I have a native char* buffer containing an RGBA image. The problem seems to be that it is a real RGBA format, and not the windows style ARGB. (which stands for BGRA, backwards)
The object must be created from the buffer without copying it.
So far, I'm using a BitmapSource
that is created from the buffer using:
BitmapSource::Create Method (Int32, Int32, Double, Double, PixelFormat, BitmapPalette, IntPtr, Int32, Int32)
I have tried System::Drawing::Bitmap, But unfortunately it seems to only support window's ARGB format, and not "normal" RGBA.
Now I would like have a DeleteObject(BitmapSource ^ )
function to free the buffer it is using. It should be called after object's use.
With the Bitmap it is quite simple:
void DeleteObject(Bitmap^ bmp)
{
if (bmp == nullptr)
{
return;
}
Rectangle rect(0, 0, bmp->Width, bmp->Height);
System::Drawing::Imaging::BitmapData^ bmpData =
bmp->LockBits(rect, System::Drawing::Imaging::ImageLockMode::ReadWrite,
bmp->PixelFormat);
delete [] (char*) bmpData->Scan0->ToPointer();
bmp->UnlockBits(bmpData);
bmp->~Bitmap();
}
I would like to do something similar with the BitmapSource (or anything else that may use RGBA).
How can i safely free the BitmapSource
buffer ?
How can i get the underlying buffer of a BitmapSource
?
I don't mind using any other C# object that can use and display an RGBA buffer (real RGBA, not windows style ARGB).