C# 图片放大、缩小

来源:互联网 发布:js的与或非用法 编辑:程序博客网 时间:2024/05/01 10:02


把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;

原创粉丝点击