473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DrawImage question

Using DrawImage I draw (in OnPaint) a bitmap on a form

protected override void OnPaint(PaintEventArgs e)
{
if (_album.Count 0)
{
// Paint the current image
Photograph photo = _album.CurrentPhoto;
Graphics g = e.Graphics;
......
g.DrawImage(photo.Image, this.DisplayRectangle);
}

All works, but when I drug the corner of the form (resize the form i
horizontal direction) the picture is redrawn incorrectly. Namely: it
should be stretched, but instead of stretching it draws some pieces of
the original image several times. It stretches too, but also repeats
the fragments. The effect is "accumulative". I other words: the more
you move, the more junk you see.

xppro, sp2, net 1.1, vs 2003

Nov 10 '06 #1
6 2528
I have some questions for you:
1.- Why you don't use a PictureBox?
2.- If the PictureBox don't serves your need, why don't do a class that
encapsulate the Picture(s)?

Regards,

Bela Istok

"Lev Elbert" <el*******@hotmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
Using DrawImage I draw (in OnPaint) a bitmap on a form

protected override void OnPaint(PaintEventArgs e)
{
if (_album.Count 0)
{
// Paint the current image
Photograph photo = _album.CurrentPhoto;
Graphics g = e.Graphics;
......
g.DrawImage(photo.Image, this.DisplayRectangle);
}

All works, but when I drug the corner of the form (resize the form i
horizontal direction) the picture is redrawn incorrectly. Namely: it
should be stretched, but instead of stretching it draws some pieces of
the original image several times. It stretches too, but also repeats
the fragments. The effect is "accumulative". I other words: the more
you move, the more junk you see.

xppro, sp2, net 1.1, vs 2003

Nov 10 '06 #2
Lev Elbert wrote:
Using DrawImage I draw (in OnPaint) a bitmap on a form

protected override void OnPaint(PaintEventArgs e)
{
if (_album.Count 0)
{
// Paint the current image
Photograph photo = _album.CurrentPhoto;
Graphics g = e.Graphics;
......
g.DrawImage(photo.Image, this.DisplayRectangle);
}

All works, but when I drug the corner of the form (resize the form i
horizontal direction) the picture is redrawn incorrectly. Namely: it
should be stretched, but instead of stretching it draws some pieces of
the original image several times. It stretches too, but also repeats
the fragments. The effect is "accumulative". I other words: the more
you move, the more junk you see.

xppro, sp2, net 1.1, vs 2003
Hi,

You need to clean your canvas before you paint your image. Use
FillRectangle to blank out the entire area first, then use DrawImage.
Also, try using this.ClientRectangle as opposed to DisplayRectangle.

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 10 '06 #3
1.- Why you don't use a PictureBox?

This is a study of .net. Looks like I found a bug :) I checked on 2
machines. Besides, PictureBox has the same problem.

Nov 10 '06 #4
Lev Elbert wrote:
>1.- Why you don't use a PictureBox?

This is a study of .net. Looks like I found a bug :) I checked on 2
machines. Besides, PictureBox has the same problem.
Hi,
Looks like I found a bug
Don't automatically assume this! You may just be getting the same behaviour
on both machines because your code is executing the same... which in fact
it is.

And it's not a bug! The reason you're seeing this behaviour is because your
painting routine doesn't clear the area that you're trying to paint to, and
when you resize the form your exposing an area of the form that has not
been painted.

This is undefined behaviour, and Windows will draw whatever lies on the edge
of the undefined area. You need to put something there.

I made a post talking about a solution, but in hindsight, the other problem
is that your painting code is not getting called when you resize your form.
You need to make sure this happens by using this.SetStyle(...) in your
form's constructor to tell the form to redraw on resize, using the
ControlStyles.ResizeRedraw setting.

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 10 '06 #5
You need to clean your canvas before you paint your image. Use
FillRectangle to blank out the entire area first, then use DrawImage.
Also, try using this.ClientRectangle as opposed to DisplayRectangle.
Before I posted the question I tryed blanking the form (both
FillRectangle and Graphics.Clear(SystemColors.Control)) - the same
result.

In my case ClientRectangle is the same as DisplayRectangle.

But thank you anyway. I think this is a bug eather in .net or in the
video driver.

Nov 10 '06 #6
I found a solution! Not sure that this one is THE solution, but anyway.

I have to handle Resize message calll Invalidate() in the handler. Al
works

Lev Elbert wrote:
Using DrawImage I draw (in OnPaint) a bitmap on a form

protected override void OnPaint(PaintEventArgs e)
{
if (_album.Count 0)
{
// Paint the current image
Photograph photo = _album.CurrentPhoto;
Graphics g = e.Graphics;
......
g.DrawImage(photo.Image, this.DisplayRectangle);
}

All works, but when I drug the corner of the form (resize the form i
horizontal direction) the picture is redrawn incorrectly. Namely: it
should be stretched, but instead of stretching it draws some pieces of
the original image several times. It stretches too, but also repeats
the fragments. The effect is "accumulative". I other words: the more
you move, the more junk you see.

xppro, sp2, net 1.1, vs 2003
Nov 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeroen Ceuppens | last post by:
Hi, When i do this in my programma, in the contstructor of the form: g.DrawImage(i,new Rectangle(0,0,i.Width,i.Height),0,0,i.Width,i.Height,GraphicsUnit.Pixel); it doens't paint it ;( but if...
1
by: Ivan | last post by:
Hi there I'm trying to use BitBlt function instead od DrawImage beacuse I need speed in my app. I have one Bitmap (bmp) that is loaded from file and I use it in OnPaint for drawing. Currently I...
5
by: Frecklefoot | last post by:
I'm using DrawImage() to copy one image onto another, larger one. I'm using a DrawImage() overload to stretch the source image onto the destination. The problem is that when it draws the stretched...
1
by: Ajay | last post by:
Hello Guys, Iam working on a zoom in and out tool and here is the code iam using for it //Method for zooming in Bitmap bmpSource=new Bitmap(ImgBox.Image); Bitmap bmpZoomed=new...
0
by: news | last post by:
Hi guys, Am I right in thinking that the DrawImage method will only render in 8bits/pixel ? I have the following code (assume my16bitImage is a 16bit bitmap in memory) .... myMatrix = new...
0
by: Jon Slaughter | last post by:
I'm manually displaying images in a TreeView but when I stick the images in the Images(icons) container in the TreeView and use DrawImage they look like crap but when I force an icon draw and use...
0
by: Lev Elbert | last post by:
Hi! Jus a simple form. Using DrawImage I draw (in OnPaint) a bitmap. protected override void OnPaint(PaintEventArgs e) { if (_album.Count 0) { // Paint the current image Photograph photo =...
1
by: Marco Trapanese | last post by:
Hello! I know GDI+ are very slow, DrawImage method is one of the slowest methods (as confirmed by a code profiler ran on my application). I have not spare time to rewrite the paint routine...
8
by: Phil | last post by:
Is it possible to find the size of the MDIClient area, excluding the space already used by docked controls? I have thought I could perhaps create a new control, set it's Dock property to Fill and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.