This project has moved and is read-only. For the latest updates, please go here.


Oct 15, 2013 at 12:32 PM
i have a Question about the library.
(Magick.NET- I copied the two files to my release folder and add a reference to my project)

I use the following code to display a image in a PictureBox.
pictureBox1.Image = new MagickImage(memoryStream).ToBitmap();
If i try to flip this image with the following code, i get a "OutOfMemoryException".
private Image flipImage(Image image, Boolean yAxis)
        Image flippedImage = new Bitmap(image.Width, image.Height);

        using (Graphics g = Graphics.FromImage(flippedImage))
                Matrix mat = null;

                if (yAxis)
                    mat = new Matrix(1, 0, 0, -1, 0, 0);
                    mat.Translate(0, flippedImage.Height, MatrixOrder.Append);
                    mat = new Matrix(-1, 0, 0, 1, 0, 0);
                    mat.Translate(flippedImage.Width, 0, MatrixOrder.Append);

                g.Transform = mat;
                g.DrawImage(image, 0, 0);      <-------- Exception

                //clean up
            return flippedImage;
If i used this code with the same picture,and flip the image, i get no Exception.
pictureBox1.Image = Bitmap.FromStream(memoryStream);
Any advices?
Oct 15, 2013 at 1:49 PM
Can you post an example image that works with Bitmap.FromStream(memoryStream); but crashes with new MagickImage(memoryStream).ToBitmap()?
Oct 15, 2013 at 2:15 PM
Edited Oct 15, 2013 at 2:15 PM
Sure, i have included a png and a dds file.

I get the same error, when i load one of these files from a path and flip the image.
pictureBox1.Image = new MagickImage(open_Dlg.FileName).ToBitmap();  <----- Exception
pictureBox1.Image = Bitmap.FromFile(open_Dlg.FileName);                      <----- works
Link images
Oct 15, 2013 at 3:31 PM
Can you create an example that does not use the picture box? Your example does not explain how the flipImage method is called. Maybe you are forgetting to Dispose the image you use when you call the flipImage method?
Oct 15, 2013 at 3:45 PM
I hope i understand what you want.

With this code i get the exception.
Image originalImage = new MagickImage(openFile_Dlg.FileName).ToBitmap();
Image img = flipImage(originalImage, true);
This code works:
Image originalImage1 = Bitmap.FromFile(openFile_Dlg.FileName);
Image img1 = flipImage(originalImage1, true);
Oct 15, 2013 at 10:33 PM
Edited Oct 15, 2013 at 10:34 PM
I can reproduce the problem. I am loading the Bitmap from a MemoryStream. After creating the Bitmap I now Dispose the MemoryStream. But according to the documentation ( I should not do this. I will create a work item to fix this and also use the constructor of Bitmap that accepts a MemoryStream instead of using the Image.FromStream method.
Oct 15, 2013 at 10:36 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.