[英]Apply ScaleTransform to Graphics GDI+
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; 现在我想将
ScaleTransform
应用到它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
). 转换应用于图形对象的变换矩阵(
g.Transform
)。
Also make use of the using
statement in order to dispose the resources. 还要使用
using
语句来处理资源。 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. 如果发生异常,或者如果
using
语句块应该留下return
或break
语句,它甚至会处理笔。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.