应用ScaleTransform以图形GDI + [英] Apply ScaleTransform to Graphics GDI+
问题描述
我已经把这个简单的代码放在一起画一条线。现在我想以10倍到应用 ScaleTransform
它;但下面的代码不能正常工作。
VAR位=新位图(pictureBox1.Size.Width,pictureBox1.Size.Height );
变种G = Graphics.FromImage(位图);
pictureBox1.Image =位图;
无功PN =新朋(Color.Wheat,-1);
g.DrawLine(PN,0,0,10,10);
pn.Dispose();
//我想在这里scaletransform!
g.ScaleTransform(10,10);
更新:
什么是正确的方法来更新的变化?我没有从这个得到任何结果:(
g.ScaleTransform(1,1);
pictureBox1。无效();
您必须申请改造前绘图!行
VAR G = Graphics.FromImage(位);
g.ScaleTransform(10,10);使用(PN =新笔(Color.Wheat,-1)){
g.DrawLine(PN,0,0,10,10);
}
转换应用到图形的变换矩阵对象( g.Transform
)。
另外,还要以配置资源使用使用
语句,它甚至会处置笔如有异常应该发生,或者如果使用
语句块应该留下一个收益
或破
语句。
I have put this simple code together to draw a line. Now I want to apply a ScaleTransform
to it by a factor of 10; but the code below doesn't work.
var bitmap = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height);
var g = Graphics.FromImage(bitmap);
pictureBox1.Image = bitmap;
var pn = new Pen(Color.Wheat, -1);
g.DrawLine(pn, 0, 0, 10, 10);
pn.Dispose();
// I'm trying to scaletransform here!
g.ScaleTransform(10, 10);
Update:
What is the correct way to update the changes? I'm not getting any results from this :(
g.ScaleTransform(1, 1);
pictureBox1.Invalidate();
You must apply the transformation BEFORE drawing the line!
var g = Graphics.FromImage(bitmap);
g.ScaleTransform(10, 10);
using (pn = new Pen(Color.Wheat, -1)) {
g.DrawLine(pn, 0, 0, 10, 10);
}
Transformations are applied to the transformation matrix of the graphics object (g.Transform
).
Also make use of the using
statement in order to dispose the resources. It will even dispose the pen if an exception should occur or if the using
statement-block should be left with a return
or break
statement.
这篇关于应用ScaleTransform以图形GDI +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!