This project has moved. For the latest updates, please go here.

image.Extent how to get transparent background

Aug 16, 2013 at 12:25 AM
I am experimenting with Magick.NET, and am trying to get a transparent background. I can get this to work with code like the following, but I think this is a hack, and not the correct way to do this. What would be the correct way to accomplish this?
MagickImage image = new MagickImage(sPath + "Render3D1.jpg");
image.Resize(300, 300);
image.Format = MagickFormat.Png;
var geometry = new ImageMagick.MagickGeometry(300, 300);
var gravity = new ImageMagick.Gravity();
var backgroundColor = new ColorMono(false); //* Hack??
gravity = Gravity.Center;
image.Extent(geometry, gravity, backgroundColor);
image.Write(sPath + "Render3D1_300_WthGeometry.png");
Coordinator
Aug 16, 2013 at 5:10 AM
You actually found a bug, it's not a feature. It should be white instead of transparent. This will be fixed in the next release. You can do this:
using (MagickImage image = new MagickImage(sPath + "Render3D1.jpg")
{
  image.Resize(300, 300);
  image.Format = MagickFormat.Png;
  // There is an implicit cast from System.Drawing.Color to MagickColor.
  image.Extent(300, 300, Gravity.Center, System.Drawing.Color.Transparent);
  image.Write(sPath + "Render3D1_300_WthGeometry.png");
}
I will create a static property MagickColor.Transparent so you won't have to use System.Drawing.
Aug 16, 2013 at 8:28 PM

Thank you. Your efforts are much appreciated. This is a great project you are doing!

Do you take donations anywhere?

Tom McEwen

AnchorCove Publishing, Inc.

www.anchorcovepublishing.com

[email removed]

Phone: 303-972-0099

Coordinator
Aug 17, 2013 at 4:57 AM
Aug 17, 2013 at 9:01 PM

Anything more preferred from that list? If not I’ll just pick one I would probably like.

Tom McEwen

AnchorCove Technology, Inc.

www.anchorcovetech.com

[email removed]

Phone: 303-972-0099

Coordinator
Aug 17, 2013 at 9:52 PM
Feel free to pick one yourself.
Coordinator
Aug 18, 2013 at 10:33 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.