aladeen
aladeen
2017-03-07 05:04
采纳率: 77.8%
浏览 3.5k

C#中pictureBox改变图片大小

如何使用鼠标滚轮仅改变图片的大小,而不改变pictureBox的大小

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • fight_in_dl
    战在春秋 2017-03-07 06:01
    已采纳
    点赞 评论
  • sjm630162
    泰兰德爱媳妇 2017-03-07 06:03

    private Image myBitmap;
    private float h;
    private float w;
    private float x;
    private float y;
    private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
    {
    Graphics g = this.pictureBox1.CreateGraphics();
    //消除锯齿
    g.SmoothingMode = SmoothingMode.AntiAlias;
    //高质量,低速度绘制
    g.CompositingQuality = CompositingQuality.HighQuality;

                g.Clear(Color.White);
                h = h + e.Delta;
                w = w + e.Delta;
                x = this.pictureBox1.Width / 2 - w / 2;
                y = this.pictureBox1.Height / 2 - h / 2;
                RectangleF rt =new RectangleF(x,y,w,h);
                g.DrawImage(myBitmap, rt);
        }
    
        private void Form9_Load(object sender, EventArgs e)
        {
             myBitmap = System.Drawing.Image.FromFile(@"d:\aa.png");
             h = myBitmap.Height;
             w = myBitmap.Width;
             pictureBox1.Image = myBitmap;
        }
    
    点赞 评论
  • sjm630162
    泰兰德爱媳妇 2017-03-07 06:11

    在pictureBox的鼠标滚轮事件里面重绘图片就行
    private Image myBitmap;
    private float h;
    private float w;
    private float x;
    private float y;
    private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
    {
    Graphics g = this.pictureBox1.CreateGraphics();
    //消除锯齿
    g.SmoothingMode = SmoothingMode.AntiAlias;
    //高质量,低速度绘制
    g.CompositingQuality = CompositingQuality.HighQuality;

                g.Clear(Color.White);
                h = h + e.Delta;
                w = w + e.Delta;
                x = this.pictureBox1.Width / 2 - w / 2;
                y = this.pictureBox1.Height / 2 - h / 2;
                RectangleF rt =new RectangleF(x,y,w,h);
                g.DrawImage(myBitmap, rt);
        }
    
        private void Form9_Load(object sender, EventArgs e)
        {
             myBitmap = System.Drawing.Image.FromFile(@"d:\aa.png");
             h = myBitmap.Height;
             w = myBitmap.Width;
             pictureBox1.Image = myBitmap;
        }
    
    
    
    点赞 评论

相关推荐