pictureBox sizemode=zoom时图片像素坐标

转自http://blog.csdn.net/lysc_forever/article/details/39530451


  1. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)  
  2. {  
  3.     int originalWidth = this.pictureBox1.Image.Width;  
  4.     int originalHeight = this.pictureBox1.Image.Height;  
  5.   
  6.     PropertyInfo rectangleProperty = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);  
  7.     Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(this.pictureBox1, null);  
  8.   
  9.     int currentWidth = rectangle.Width;  
  10.     int currentHeight = rectangle.Height;  
  11.   
  12.     double rate = (double)currentHeight / (double)originalHeight;  
  13.   
  14.     int black_left_width = (currentWidth == this.pictureBox1.Width) ? 0 : (this.pictureBox1.Width - currentWidth) / 2;  
  15.     int black_top_height = (currentHeight == this.pictureBox1.Height) ? 0 : (this.pictureBox1.Height - currentHeight) / 2;  
  16.   
  17.     int zoom_x = e.X - black_left_width;  
  18.     int zoom_y = e.Y - black_top_height;  
  19.   
  20.     double original_x = (double)zoom_x / rate;  
  21.     double original_y = (double)zoom_y / rate;  
  22.   
  23.     StringBuilder sb = new StringBuilder();  
  24.   
  25.     sb.AppendFormat("原始尺寸{0}/{1}(宽/高)\r\n", originalWidth, originalHeight);  
  26.     sb.AppendFormat("缩放状态图片尺寸{0}/{1}(宽/高)\r\n", currentWidth, currentHeight);  
  27.     sb.AppendFormat("缩放比率{0}\r\n", rate);  
  28.     sb.AppendFormat("左留白宽度{0}\r\n", black_left_width);  
  29.     sb.AppendFormat("上留白高度{0}\r\n", black_top_height);  
  30.     sb.AppendFormat("当前鼠标坐标{0}/{1}(X/Y)\r\n", e.X, e.Y);  
  31.     sb.AppendFormat("缩放图中鼠标坐标{0}/{1}(X/Y)\r\n", zoom_x, zoom_y);  
  32.     sb.AppendFormat("原始图中鼠标坐标{0}/{1}(X/Y)\r\n", original_x, original_y);  
  33.     this.label1.Text = sb.ToString();  
  34.   
  35. }  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值