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

Composite Image

May 13, 2014 at 4:32 PM
I have having a memory access error here and from what I can tell it is written correctly.
I am trying to take an image and put it on the badge image I have open in a certain location using the Geomerty.
                MagickGeometry photo = new MagickGeometry(0, 0, 1000,1000);
                MagickImage employeePhoto = new MagickImage(new System.Drawing.Bitmap(employeePictureBox.Image));

                DrawableCompositeImage drawEmployeePhoto = new DrawableCompositeImage(photo, employeePhoto);  // Memory Access error.

                badge.Draw(new Drawable[] { drawEmployeePhoto });
Any Ideas?
Coordinator
May 13, 2014 at 6:48 PM
This is most likely a bug in Magick.NET. Can you provide me with the 2 images so I can try to reproduce the problem. Do you have some example images that you can share publicly? If that is not possible you could also contact me trough Codeplex to send the images to me personally.
May 13, 2014 at 6:55 PM
Why would it be photo specific?
Coordinator
May 13, 2014 at 7:00 PM
Edited May 13, 2014 at 7:32 PM
I don't know if it is but it will make it easier for me to reproduce the problem. Can you provide me with the dimensions of the two images? Then I will give it a try with two of my images.

Edit: I can reproduce the problem and a fix for this will be available in the next release of Magick.NET.
May 13, 2014 at 8:13 PM
Sent you the photos in an email.
Coordinator
May 13, 2014 at 8:57 PM
Edited May 13, 2014 at 8:57 PM
Thank you for the images. The bug has been fixed and the code below is a workaround that uses MagickImage.Composite instead of DrawableCompositeImage
using (MagickImage badge = new MagickImage("BLANK_BADGE.png"))
{
  int left = 491;
  int height = 952;

  MagickGeometry offset = new MagickGeometry(left, 0, 0, 0);

  // This looks better but you probably don't need it.
  badge.Draw(
    new DrawableFillColor(Color.White),
    new DrawableRectangle(left, 0, badge.Width, height));

  using (MagickImage employee = new MagickImage("Employee.jpg"))
  {
    // Draw the photo
    employee.Resize(badge.Width - left, height);
    offset.Y = height - employee.Height;
    badge.Composite(employee, offset, CompositeOperator.Over);

    // Draw the employee number
    badge.Draw(
      new DrawableFillColor(Color.Red),
      new DrawableFont("Verdana"),
      new DrawablePointSize(50),
      new DrawableTextAntialias(true),
      new DrawableText(180, 820, "1337"));

    badge.Write("BADGE.Employee.png");
  }
}
May 13, 2014 at 9:11 PM
Thanks for getting the library fixed.
The sample code was just a test of concept before it was implemented.