把pictureBox1的SizeMode属性设置为StretchImage
定义变量:
Bitmap img; // 保存原图
int width; // 当前显示部分的宽度
int height; // 当前显示部分的高度
初始化:
width = pictureBox1.Width;
height = pictureBox1.Height;
img = new Bitmap("Autumn.jpg"); // 从文件获取图片并显示在pictureBox1中:
bmp = new Bitmap(width, height);
Point pt = new Point(0, 0);
g.DrawImage(img, pt.X, pt.Y);
pictureBox1.Image = bmp;
点击鼠标后的处理:
width += 50;
height += 50;
bmp = new Bitmap(width, height );
Graphics g = Graphics.FromImage(bmp);
Point pt = new Point(0, 0);
g.DrawImage(img, pt.X, pt.Y);
pictureBox1.Image = bmp;
C# 图片放大、缩小
最新推荐文章于 2024-03-24 14:45:26 发布