System.Drawing.Graphics.Transform在Ubuntu下的Mono中没有任何效果

时间:2012-05-04 12:38:06

标签: graphics mono system.drawing

我有一个非常简单的代码,可以在位图上绘制图像,图像必须在右下角绘制。我使用TranslateTransform来移动图像。这在Windows下运行时工作正常,但是,在Linux下以Mono运行时,TranslateTransform无效。

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 corner.
            gr.TranslateTransform(400,400);

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

当然,代码是真实代码的简化版本,必须在Windows和Linux环境中都能运行。我缩小了代码,发现linux下的问题发生是因为Graphics.Transform对linux下的Mono没有影响。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

我认为最简单的解决方案是简单地将d添加400到dstPoints的X和Y组件。