Graphics g = pictureBox1.CreateGraphics(); g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, xWidth, yHeight), //where to draw the image new Rectangle(x, y, xWidth, yHeight), //the portion of the image to draw x,y是自己定义的大小. GraphicsUnit.Pixel); 具体可参考MSDN的Graphics.DrawImage()方法.有好多重载.
Graphics g = pictureBox1.CreateGraphics(); g.DrawImage(pictureBox1.Image, new Rectangle(300, 300, 300,300), GraphicsUnit.Pixel); 我用这个它说重载方法有无效参数。。 然后我把那个指定单位是像素的GraphicsUnit.Pixel去掉 没错了 可是运行了之后图像显示没变化啊
g.DrawImage(pictureBox1.Image,
new Rectangle(0, 0, xWidth, yHeight), //where to draw the image
new Rectangle(x, y, xWidth, yHeight), //the portion of the image to draw x,y是自己定义的大小.
GraphicsUnit.Pixel);
具体可参考MSDN的Graphics.DrawImage()方法.有好多重载.
g.DrawImage(pictureBox1.Image,
new Rectangle(300, 300, 300,300),
GraphicsUnit.Pixel); 我用这个它说重载方法有无效参数。。
然后我把那个指定单位是像素的GraphicsUnit.Pixel去掉
没错了 可是运行了之后图像显示没变化啊
public void DrawImage (
Image image,
RectangleF destRect,
RectangleF srcRect,
GraphicsUnit srcUnit
)
参数
image
要绘制的 Image。 destRect
RectangleF 结构,它指定所绘制图像的位置和大小。将图像进行缩放以适合该矩形。 srcRect
RectangleF 结构,它指定 image 对象中要绘制的部分。 srcUnit
GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。
恩,找到代码了
代码段我是放在指定了pictureBox的图像地址之后,应该没问题的吧?
pictureBox1.Update();