| |

VerySource

 Forgot password?
 Register
Search
View: 1728|Reply: 11

How do I scale a picture with a point as the center?

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-19 08:20:01
| Show all posts |Read mode
Hello everyone!
    I put a picturebox in the panel. If the picture is too large, the panel cannot display the whole picture. I want to scale a part of the picture displayed by the panel, and the center of the rectangle is the center to scale the picture.
    Another problem is how to call the middle mouse button to achieve zooming.
    Thank you!
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-26 14:18:02
| Show all posts
Just set the SizeMode property of the picturebox to Zoom.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-26 18:09:02
| Show all posts
Upstairs solution
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Unknown

 Author| Post time: 2020-1-31 20:18:01
| Show all posts
So how to call the middle mouse wheel to zoom? Thank you
Reply

Use magic Report

1

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-2-5 18:30:01
| Show all posts
The pulley seems to be triggered by an event
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-9 08:00:01
| Show all posts
Even here is a demo, very simple zooming. You can contact me if needed.
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-26 14:30:02
| Show all posts
I post the code here.
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-26 16:15:01
| Show all posts
private Point mousePosition = new Point (0, 0);

        public Form1 ()
        {
            InitializeComponent ();
        }

        private void minPanel_Paint (object sender, PaintEventArgs e)
        {
            Graphics g = this.minPanel.CreateGraphics ();
            Image img = Image.FromFile (Application.StartupPath + @ "\7.jpg");
            g.DrawImage (img, this.minPanel.ClientRectangle, 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);

        }

        private void minPanel_MouseDown (object sender, MouseEventArgs e)
        {
            this.controlframe.Left = e.X;
            this.controlframe.Top = e.Y;
            DrawBig ();
            DrawSmall ();
        }

        private void controlframe_Paint (object sender, PaintEventArgs e)
        {
            DrawSmall ();
        }

        private void controlframe_MouseUp (object sender, MouseEventArgs e)
        {
            DrawSmall ();

            DrawBig ();
        }

        private void controlframe_MouseMove (object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (e.X> = 0&&e.X <= this.minPanel.ClientRectangle.Width&&e.Y> = 0&&e.Y <= this.minPanel.ClientRectangle.Height)
                {
                    this.controlframe.Left = e.X + this.mousePosition.X;
                    this.controlframe.Top = e.Y + this.mousePosition.Y;
                    DrawSmall ();
                    DrawBig ();
                }
            }
        }

        private void controlframe_MouseDown (object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.mousePosition.X = this.controlframe.Left;
                this.mousePosition.Y = this.controlframe.Top;
                this.DrawSmall ();
                this.DrawBig ();
                //this.Dispose;
            }
        }

        private void DrawSmall ()
        {
            Graphics g = this.controlframe.CreateGraphics ();
            Bitmap bmp = new Bitmap ((Bitmap) Bitmap.FromFile (Application.StartupPath + @ "\7.jpg"), new Size (this.minPanel.Width, this.minPanel.Height));
            g.DrawImage (bmp, this.controlframe.ClientRectangle, this.controlframe.Left, this.controlframe.Top, this.controlframe.ClientRectangle.Width, this.controlframe.ClientRectangle.Height, System.Drawing.GraphicsUnit.Pixel);
            g.Dispose ();
            this.controlframe.Update ();
        }

        private void DrawBig ()
        {
            Graphics g = this.maxPanel.CreateGraphics ();
            Image img = Image.FromFile (Application.StartupPath + @ "\7.jpg");
            g.DrawImage (img, this.maxPanel.ClientRectangle, this.controlframe.Left, this.controlframe.Top, this.maxPanel.ClientRectangle.Width, this.maxPanel.ClientRectangle.Height, System.Drawing.GraphicsUnit.Pixel);
            g.Dispose ();
            this.minPanel.Update ();
        }
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-30 13:00:02
| Show all posts
up
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-5 22:30:01
| Show all posts
The pulley is triggered by an event, but how to judge
Does the pulley roll up and down?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list