2012-05-04 1 views
0

비트 맵에 이미지를 그리는 아주 간단한 코드가 있습니다. 이미지는 오른쪽 아래 모서리에 그려야합니다. 나는 TranslateTransform을 사용하여 이미지를 움직인다. Windows에서 실행할 때 잘 작동하지만 Linux에서 Mono로 실행할 때 TranslateTransform은 아무 효과가 없습니다.System.Drawing.Graphics.Transform은 Mono 우분투에서 효과가 없습니다.

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 환경에서 모두 작동해야하는 실제 코드의 단순화 된 버전입니다. 나는 코드를 좁히고 Graphics.Transform이 리눅스에서 Mono에 아무런 영향을 미치지 않기 때문에 리눅스에서 발생하는 문제를 발견했다. 어떤 아이디어?

답변

0

가장 쉬운 해결책은 dstPoint의 X 및 Y 구성 요소에 400을 단순히 추가하는 것입니다.

+0

예 :) 또는 단순히 dstPoints를 변환 할 수 있지만 모든 경우 (예 : 텍스트 회전)에는 작동하지 않습니다. 그래서 어떻게 든 변형 작업을해야합니다. – alex

+0

위의 문제를 도와 줄 사람이 있습니까? – alex