[Mono-list] System.Drawing.Graphics.Transform has no effect in Mono under Linux

alex student_hire at mail.ru
Mon May 7 06:18:49 UTC 2012

I have a very simple code that draws an image on a bitmap, the image must be
drawn in the lower right corner. I use TranslateTransform to move the image.
This works fine when run under Windows, however, TranslateTransform has no
effect when run in Mono under Linux.

byte[] imageBytes = File.ReadAllBytes(@"/home/alexey/Downloads/test.png");
using (Bitmap bmp = new Bitmap(500, 500))
    using (Graphics gr = Graphics.FromImage(bmp))
        ImageAttributes attr = null;

        using (Image image = Image.FromStream(new MemoryStream(imageBytes)))
            GraphicsUnit srcGU = GraphicsUnit.Pixel;
            RectangleF srcRect = image.GetBounds(ref srcGU);
            RectangleF bounds = new RectangleF(0, 0, 100, 100);

            // Destination points specify the bounding parallelogram.
            PointF[] dstPoints = new PointF[]
                { bounds.Location,
                  new PointF(bounds.X + bounds.Width, bounds.Y),
                  new PointF(bounds.X, bounds.Y + bounds.Height) };

            // Image must be in the in the lower right corner and it is if
run the code under Windows.
            // But is run code under linux, the image is in the upper left

            gr.DrawImage(image, dstPoints, srcRect, srcGU, attr);
    bmp.Save(@"/home/alexey/Downloads/out.png", ImageFormat.Png);

Of course, the code is a simplified version of the real code that must work
in both windows and Linux environments. I narrowed down the code and found
that the problems under linux occur because Graphics.Transform has no effect
in Mono under linux. Any ideas?

I posted the same on stackoverflow:

View this message in context: http://mono.1490590.n4.nabble.com/System-Drawing-Graphics-Transform-has-no-effect-in-Mono-under-Linux-tp4614100.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list