| |

VerySource

 Forgot password?
 Register
Search
View: 1458|Reply: 10

Use GDI+ to draw a 2000-pixel-wide picture in the panel control on the form, and the picture is not complete when draggi

[Copy link]

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-9-25 13:30:02
| Show all posts |Read mode
Use GDI+ to draw a 2000-pixel-wide picture in the panel control on the form. When dragging the scroll bar, the picture is not drawn completely. It seems to be drawn slowly, and the image cannot be scrolled smoothly. Drag which direction to which direction There is a small area between the picture and the edge of the form that cannot be drawn. When the drag is fast, the area between the picture and the edge of the form will be large, and the area of ​​the picture will be small if the picture is slow. , It seems to have something to do with the speed of dragging the scroll bar. I tried NNNN times, and after thinking of many ways, it is still the same! There is really no way! Is it the efficiency of GDI+? Shouldn't it   drawing a picture will have this problem? I think there should be something wrong with my code, the code is as follows, forgot to say, my form is a subform
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MapEdit
{
    public partial class newMap: Form
    {
        private Image im;//Image object
               
        private Graphics g;
        private Graphics g1;
        private Bitmap curBitmap;
        
        public newMap(int MapW,int MapH,int TitleW,int TitleH)
        {
            InitializeComponent();

                       
        }
               
        private void newMap_Load(object sender, EventArgs e)
        {
            im = Image.FromFile("image.gif");
            panel1.Width = im.Width;
            panel1.Height = im.Height;
            
            g = this.panel1.CreateGraphics();
            g.Clear(Color.Black);
            curBitmap = new Bitmap(im.Width, im.Height);
            g1 = Graphics.FromImage(curBitmap);
            g1.DrawImage(im, 0, 0, im.Width, im.Height);
        }
        
        private void newMap_Paint(object sender, PaintEventArgs e)
        {
           
            g.DrawImage(curBitmap, 0, 0);
           
        }
        
    }
}
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Invalid IP Address

Post time: 2020-9-26 15:30:02
| Show all posts
1\Put the pictureBox in the panel and set the panel scroll bar to auto
2\Create a BitMap and draw the picture on the bitmap
3\picturebox.image=bitmap
I don't know if I say this is what you mean
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-9-26 15:45:01
| Show all posts
What I'm talking about is not showing the picture, but when dragging the scroll bar, the picture scrolling is not smooth, and sometimes the picture on the form cannot be drawn. I want to know if it is the GDI+ effect or the problem with my code.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-26 16:30:01
| Show all posts
Oh funny meaning,
I suggest this can be solved.

After GDI+ draws to the memory canvas, let the picBox control point to it, and then turn on the double buffering of the picbox. And set the scroll bar.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-26 16:45:01
| Show all posts
Now the efficiency of C#GDI+ direct drawing is really not high.
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-9-26 17:00:01
| Show all posts
Oh funny meaning,
I suggest this can be solved.

After GDI+ draws to the memory canvas, let the picBox control point to it, and then turn on the double buffering of the picbox. And set the scroll bar.
------------------
I have used double buffering but it has no effect.   I can’t figure out the reason. I don’t think the efficiency of GDI+ is so low, so I think it’s my cause, but I don’t understand the problem. Months:(
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-9-26 17:15:01
| Show all posts
If it is to set the iamge property of the picturebox instead of drawing on the panel, it should be a control problem, not a GDI problem, right?
I used the method I said to draw an image with 7000+ pixels, and there is no problem with you when I move it. My cpu is only Celeron 2.0.
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-9-26 17:30:01
| Show all posts
If it is to set the iamge property of the picturebox instead of drawing on the panel, it should be a control problem, not a GDI problem, right?
I used the method I said to draw an image with 7000+ pixels, and there is no problem with you when I move it. My cpu is only Celeron 2.0.
-----------------------------------
I need to use GDI+ to change the image. Can this method work?   I will try, thank you very much!
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-9-26 17:45:01
| Show all posts
To change the image, you can change the bmp, and then set it to the image attribute update of the pictureBox.
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-9-26 18:15:01
| Show all posts
Haha The way to set the image attribute with pictureBox Yes No more unsmooth scrolling
Thank you  wxp1281brothers
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