GDI limitations dealing with panels and large images

J

Jaxson Tammaru

Create a new form, chuck a panel on and place within the panel a picturebox
of about 1000 * 5000, make an image that size set that to the image property
of the picturebox, then set the minimum size properties of the scrollbar to
1000 * 5000 and then run.
It is insanely slowwwwwwww, the refresh is so poor at times the graphic
looks completely wrong, why is this? Is this a limitation of the GDI or am I
missing something or setting up something wrong?
As it stands to get round this problem i am now looking into direct draw
(DirectX9) as i've heard this has a better re-draw rate but is this the only
solution or I am doing this work for naught? Is there a better way around
this problem?

If there is please let me know.

Jax
 
B

BMermuys

Hi, [Inline]

"Jaxson Tammaru"
<JaxsonREMOVETOSEND.TamREMOVEmaru@diaIFYOUWISHTOSENDMEAMAILREMOVETHISmetric.
org> wrote in message news:[email protected]...
Create a new form, chuck a panel on and place within the panel a picturebox
of about 1000 * 5000, make an image that size set that to the image property
of the picturebox, then set the minimum size properties of the scrollbar to
1000 * 5000 and then run.
It is insanely slowwwwwwww, the refresh is so poor at times the graphic
looks completely wrong, why is this? Is this a limitation of the GDI or am I
missing something or setting up something wrong?
As it stands to get round this problem i am now looking into direct draw
(DirectX9) as i've heard this has a better re-draw rate but is this the only
solution or I am doing this work for naught? Is there a better way around
this problem?

You can always implement your own scrolling :

1 Place a picturebox(viewport size, not image size), a vscrollbar and an
hscrollbar on a form.
Set hscrollbar max to 1000-picturebox.Width.
Set vscrollbar max to 5000-picturebox.Height.
Choose a smallchange/largechange value.
2 Attach a paint handler for the picturebox and scroll handlers for the
scrollbars.
3 Follow the implementation below :

private Image img = Image.FromFile(".....");

private void pictureBox1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
// determine visible portion
Rectangle srcRect = new Rectangle(
hScrollBar1.Value,
vScrollBar1.Value,
pictureBox1.Width,
pictureBox1.Height);

// only draw the visible portion of the image
e.Graphics.DrawImage(img, 0, 0, srcRect, GraphicsUnit.Pixel );
}

private void vScrollBar1_Scroll(object sender,
System.Windows.Forms.ScrollEventArgs e)
{
pictureBox1.Invalidate();
}

private void hScrollBar1_Scroll(object sender,
System.Windows.Forms.ScrollEventArgs e)
{
pictureBox1.Invalidate();
}



HTH,
greetings
 
J

Jaxson Tammaru

Thanks for the solution, I tested it out and it worked as you specified.
The direct draw that I am looking is is far more effective though as the GDI
solution does end up being a little jerky and therefore the Direct Draw
solution would appear to be best for potential users of this program to be
best pleased.

Thankyou very much for the solution, it certainly made me think twice about
getting in-depth with DirectX, although I am finiding it quite enjoyable
now.

Jax

BMermuys said:
Hi, [Inline]

"Jaxson Tammaru"
<JaxsonREMOVETOSEND.TamREMOVEmaru@diaIFYOUWISHTOSENDMEAMAILREMOVETHISmetric.
org> wrote in message news:[email protected]...
Create a new form, chuck a panel on and place within the panel a picturebox
of about 1000 * 5000, make an image that size set that to the image property
of the picturebox, then set the minimum size properties of the scrollbar to
1000 * 5000 and then run.
It is insanely slowwwwwwww, the refresh is so poor at times the graphic
looks completely wrong, why is this? Is this a limitation of the GDI or
am
I
missing something or setting up something wrong?
As it stands to get round this problem i am now looking into direct draw
(DirectX9) as i've heard this has a better re-draw rate but is this the only
solution or I am doing this work for naught? Is there a better way around
this problem?

You can always implement your own scrolling :

1 Place a picturebox(viewport size, not image size), a vscrollbar and an
hscrollbar on a form.
Set hscrollbar max to 1000-picturebox.Width.
Set vscrollbar max to 5000-picturebox.Height.
Choose a smallchange/largechange value.
2 Attach a paint handler for the picturebox and scroll handlers for the
scrollbars.
3 Follow the implementation below :

private Image img = Image.FromFile(".....");

private void pictureBox1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
// determine visible portion
Rectangle srcRect = new Rectangle(
hScrollBar1.Value,
vScrollBar1.Value,
pictureBox1.Width,
pictureBox1.Height);

// only draw the visible portion of the image
e.Graphics.DrawImage(img, 0, 0, srcRect, GraphicsUnit.Pixel );
}

private void vScrollBar1_Scroll(object sender,
System.Windows.Forms.ScrollEventArgs e)
{
pictureBox1.Invalidate();
}

private void hScrollBar1_Scroll(object sender,
System.Windows.Forms.ScrollEventArgs e)
{
pictureBox1.Invalidate();
}



HTH,
greetings
If there is please let me know.

Jax
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top