Picturebox实现图片的缩放

程序中要弄个简单的图片查看器,可以按比例缩放大小的,当然可以调用windows的图片查看器,不过想想还是自己动手弄个简单的吧。。

 

 

缩放操作在Picturebox重绘的时候触发执行。如下

 

代码
 
   
1 // 重绘处理部分
2   private void pipeImagePictureBox_Paint( object sender, PaintEventArgs e)
3 {
4 try
5 {
6 if (pipeImagePath != "" )
7 {
8 pipeImage = new Bitmap(pipeImagePath);
9 }
10 Graphics g = e.Graphics;
11 // 设置高质量插值法
12   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
13 // 设置高质量,低速度呈现平滑程度
14   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
15 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
16 // 消除锯齿
17   g.SmoothingMode = SmoothingMode.AntiAlias;
18
19 float fx = ( float )( this .pipeImageZoomNumericUpDown.Value / 100 );
20 float fy = ( float )( this .pipeImageZoomNumericUpDown.Value / 100 );
21 int w = ( int )(pipeImage.Width * fx), h = ( int )(pipeImage.Height * fy);
22 pipeImagePictureBox.Width = w;
23 pipeImagePictureBox.Height = h;
24 int W = ( int )(pipeImagePanel.Width), H = ( int )(pipeImagePanel.Height);
25 pipeImagePictureBox.Location = new System.Drawing.Point((W - w) / 2 , (H - h) / 2 );
26 pipeImagePictureBox.Size = new Size(w,h);
27
28 Rectangle newRectangle = new Rectangle( 0 , 0 , w, h);
29 g.DrawImage(pipeImage, newRectangle);
30 }
31 catch (Exception ex)
32 {
33 // pipeImagePictureBox.Image = null;
34   }
35 }

 

 

当然,除了缩放还有其他的要做。。

转载于:https://www.cnblogs.com/njucslzh/archive/2010/11/09/1872316.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值