HighTechTalks DotNet Forums  

how to prevent artifacts that appear when dragging objects?

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss how to prevent artifacts that appear when dragging objects? in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
SharpCoderMP
 
Posts: n/a

Default how to prevent artifacts that appear when dragging objects? - 04-25-2007 , 07:12 AM






hi,

i've created a canvas like surface on which user can place some objects
named frames. this frames can be resized, moved and filled with text or
images.
i have a problem with artifacts that appear on a drawing surface when
user quickly moves or scales these frames. i can't afford invalidating
whole canvas surface (drawing images is very expensive) so i can only
invalidate the frame area. everything works fine but only when user
performs slow movements. when the drag move is faster i get lots of
artifacts that are not redrawn.

when and how should i invalidate to prevent this? i've even created a
"safe frame" that is sort of bounding box that is larger than the frame
itself to have a bit larger invalidation area, but still this does not
help for very fast movement.

is the periodic invalidation of the whole drawing surface a reasonable
solution?

Reply With Quote
  #2  
Old   
Chris Taylor
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 04-25-2007 , 03:08 PM






Hi,

If I understand your problem correctly, one option would be to create an
invalidation rect should be the union of the initial rect and the final rect
this will invalidate the area that the movement of the frame covered.

Hope that helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


"SharpCoderMP" <csharp_mp (AT) interia (DOT) pl.NFSPM> wrote

Quote:
hi,

i've created a canvas like surface on which user can place some objects
named frames. this frames can be resized, moved and filled with text or
images.
i have a problem with artifacts that appear on a drawing surface when
user quickly moves or scales these frames. i can't afford invalidating
whole canvas surface (drawing images is very expensive) so i can only
invalidate the frame area. everything works fine but only when user
performs slow movements. when the drag move is faster i get lots of
artifacts that are not redrawn.

when and how should i invalidate to prevent this? i've even created a
"safe frame" that is sort of bounding box that is larger than the frame
itself to have a bit larger invalidation area, but still this does not
help for very fast movement.

is the periodic invalidation of the whole drawing surface a reasonable
solution?


Reply With Quote
  #3  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 04-25-2007 , 03:42 PM



You say that drawing images is expensive but have you ensured that ALL
images are 32bppPargb? If not, do that!

You really must invalidate the union of the -from- and -to- rectangles
for any paint to work correctly.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





SharpCoderMP wrote:
Quote:
hi,

i've created a canvas like surface on which user can place some objects
named frames. this frames can be resized, moved and filled with text or
images.
i have a problem with artifacts that appear on a drawing surface when
user quickly moves or scales these frames. i can't afford invalidating
whole canvas surface (drawing images is very expensive) so i can only
invalidate the frame area. everything works fine but only when user
performs slow movements. when the drag move is faster i get lots of
artifacts that are not redrawn.

when and how should i invalidate to prevent this? i've even created a
"safe frame" that is sort of bounding box that is larger than the frame
itself to have a bit larger invalidation area, but still this does not
help for very fast movement.

is the periodic invalidation of the whole drawing surface a reasonable
solution?

Reply With Quote
  #4  
Old   
Bill Woodruff
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 04-26-2007 , 04:23 PM



"Bob Powell [MVP]" wrote :

You really must invalidate the union of the -from- and -to- rectangles
for any paint to work correctly."

Hi Bob,

I'm curious if this would also apply to a scenario in which the user is
dragging/moving a picturebox around at run-time... rather than moving
something drawn directly on a form or control surface with brushes or
whatever ... as I think this scenario implies.

thanks, Bill Woodruff



Reply With Quote
  #5  
Old   
SharpCoderMP
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 04-27-2007 , 11:36 AM



thanks bob. as usual - you are the best
invalidation thing with union really helped. i must admit - it's soooo
simple solution and works just great!
as to bitmaps - i'm almost sure that they were not 32bppPArgb. i did
some modifications and now am creating only 32bppPArgb bitmaps and the
drawing speed seems to be indeed better.

i have one question about that 32bppPArgb thing. is there any
straightforward way of converting images loaded from files into that
format? for now i do something like this:

Bitmap finalImg = new Bitmap(tSize.Width, tSize.Height,
PixelFormat.Format32bppPArgb);
using(Graphics g = Graphics.FromImage(finalImage))
g.DrawImage(img,new Rectangle(new Point(0,0),tSize));
img.Dispose();


Bob Powell [MVP] wrote:
Quote:
You say that drawing images is expensive but have you ensured that ALL
images are 32bppPargb? If not, do that!

You really must invalidate the union of the -from- and -to- rectangles
for any paint to work correctly.


Reply With Quote
  #6  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 04-28-2007 , 09:28 AM



I think not Bill. When dragging any control you're relying on Windows to
manage the screen. When you do your own drawing the responsibility is on you
to manage the pixels corectly.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"Bill Woodruff" <msnwsgroups (AT) dotscience (DOT) com> wrote

Quote:
"Bob Powell [MVP]" wrote :

You really must invalidate the union of the -from- and -to- rectangles
for any paint to work correctly."

Hi Bob,

I'm curious if this would also apply to a scenario in which the user is
dragging/moving a picturebox around at run-time... rather than moving
something drawn directly on a form or control surface with brushes or
whatever ... as I think this scenario implies.

thanks, Bill Woodruff




Reply With Quote
  #7  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 04-28-2007 , 09:29 AM



Great, glad I could help.

You've done your image conversion in exactly the right way.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"SharpCoderMP" <csharp_mp (AT) interia (DOT) pl.NFSPM> wrote

Quote:
thanks bob. as usual - you are the best
invalidation thing with union really helped. i must admit - it's soooo
simple solution and works just great!
as to bitmaps - i'm almost sure that they were not 32bppPArgb. i did
some modifications and now am creating only 32bppPArgb bitmaps and the
drawing speed seems to be indeed better.

i have one question about that 32bppPArgb thing. is there any
straightforward way of converting images loaded from files into that
format? for now i do something like this:

Bitmap finalImg = new Bitmap(tSize.Width, tSize.Height,
PixelFormat.Format32bppPArgb);
using(Graphics g = Graphics.FromImage(finalImage))
g.DrawImage(img,new Rectangle(new Point(0,0),tSize));
img.Dispose();


Bob Powell [MVP] wrote:
You say that drawing images is expensive but have you ensured that ALL
images are 32bppPargb? If not, do that!

You really must invalidate the union of the -from- and -to- rectangles
for any paint to work correctly.



Reply With Quote
  #8  
Old   
active
 
Posts: n/a

Default Re: how to prevent artifacts that appear when dragging objects? - 06-01-2007 , 08:38 AM




">> Bob Powell [MVP] wrote:
Quote:
You say that drawing images is expensive but have you ensured that ALL
images are 32bppPargb? If not, do that!

Bob,

If you were creating a general purpose app that allowed the user to open
files and crop them, rotate them, draw a little on them, convert to gray
scale...

Would you convert each image to 32bppPargb after it is opened.

That is, is that the format that is the fastest and allows the most to be
done to it?


Thanks




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.