windows bitmap with alpha
Posted: 2017-06-24T04:12:51-07:00
I had a hard time creating a 32bit rgba bitmap with Magick.NET-Q16-AnyCPU / 7.0.0.0 which i got via visual studio 2017 nuget manager.
Trying to create an image with
somehow disabled the alpha channel, but
didn't?
As i couldn't find a function to fill the whole image, like drawing a filled rectangle without border which is the size of the image, i ended up creating a black image with alpha 255 like this:
It feels a little too unintuitive. Is there a better approach? Why behaves MagickImage(MagickColor.FromRgba(0, 0, 0, 255) different from MagickImage(MagickColor.FromRgba(0, 0, 0, 0) ? This is really puzzling me.
Anyway, when trying to save the image as 32bit windows bmp, alpha got stripped away and the file saved was 24bit:
Now, i read here and then there about Bmp4 and some support for Bmp3 as well but since I'm new to Magick.NET, i honestly don't have a clue what to do. Is that nuget Version too old or did I just load the wrong one?
Anyway, luckily, there's a ToBitmap member in MagickImage which seems to preserve all 32bit, so at the moment i ended up using this:
However, i would feel better using only ImageMagick types to save the bitmap.
Can this be done with Magick.NET? Is the mentioned Bmp4 type already released in a newer Magick.NET package? Is there a flag i can set which mimics the "-define bmp3:alpha=true" mentioned in that link?
Trying to create an image with
Code: Select all
var bitmap = new MagickImage(MagickColor.FromRgba(0, 0, 0, 255), size, size);
Code: Select all
var bitmap = new MagickImage(MagickColor.FromRgba(0, 0, 0, 0), size, size);
As i couldn't find a function to fill the whole image, like drawing a filled rectangle without border which is the size of the image, i ended up creating a black image with alpha 255 like this:
Code: Select all
var bitmap = new MagickImage(MagickColor.FromRgb(0, 0, 0), size, size);
bitmap.Transparent(MagickColor.FromRgb(0, 0, 0));
Anyway, when trying to save the image as 32bit windows bmp, alpha got stripped away and the file saved was 24bit:
Code: Select all
using (var os = new System.IO.FileStream("asdf.bmp", System.IO.FileMode.Create))
{
bitmap.Write(os, MagickFormat.Bmp3);
}
Anyway, luckily, there's a ToBitmap member in MagickImage which seems to preserve all 32bit, so at the moment i ended up using this:
Code: Select all
var bmp = bitmap.ToBitmap(System.Drawing.Imaging.ImageFormat.Bmp);
bmp.Save("asdf.bmp");
Can this be done with Magick.NET? Is the mentioned Bmp4 type already released in a newer Magick.NET package? Is there a flag i can set which mimics the "-define bmp3:alpha=true" mentioned in that link?