[英]How to draw at top left of metaFile
我在MetaFile中畫一條簡單的線為:
var g = CreateGraphics();
var img = new Metafile(path, g.GetHdc());
var ig = Graphics.FromImage(img);
ig.DrawLine(new Pen(Color.Black, 2), 0, 0, 300, 0);
然后,我嘗試將這個metaFile保存為png圖片,如下所示:
var target = new Bitmap(200, 100);
var g2 = Graphics.FromImage(target);
g2.DrawImage(source,0,0);// source is my MetaFile
但是該行不在圖像的頂部:(為什么以及如何執行此操作?
在將其保存到圖像之前,請嘗試處置您在代碼上使用的Graphics類:
using( Graphics graphics = Graphics.FromImage( metafile ) )
{
graphics.DrawLine(new Pen(Color.Black, 2), 0, 0, 300, 0);
} // right here in this point, the 'using' keyword launches graphics.Dispose(),
// which is very importante when using graphics
謝謝,我發現我在這里是:
var img = new Metafile(path, g.GetHdc(), new Rectangle(0, 0, 101, 101), MetafileFrameUnit.Pixel);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.