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 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
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.
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.
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.
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.
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
| |