Good Article
ReplyThis uses GDI+, which is slow as its not accelerated.
ReplyI found a simpler solution for getting double buffering that was even easier to implement:
Add the following style in the forms constructor:
base.SetStyle
(
ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,true
);
It seamed to me like the performance was better than I archived using the mechanisms you described in "The .NET way". I think this was caused by the fact that the Off-screen surface was in the computers memory in your example and hopefully in the display card memory as an off-screen surface. This would increase the blitting performance from back to front buffer significantly.
I added the above mentioned line in my form's constructor and it really worked fine........But when i tried to scroll(axis scroll of my graph) my graph still flickers, any help ???? I am desperetely seeking the solution.... Thanks in advance Sudhir
ReplyVery good article, thank you! For the pure .Net way, remember to call Dispose() on your Graphics and Bitmap instances. Simply letting the garbage collector remove them won't be enough. This is especially important for "temporary" Graphics context or Bitmaps that are created in a loop, otherwise you may notice your app behaving erratically after a while when resources get low (I've actually only started to notice that bug once I ported my game to Pocket PC using the .Net Compact framework.) All .Net classes mapping GDI+ inherit IDisposable and must be disposed properly says the documentation.Reply
Originally posted by: miro
Worked fast
not a single problem
thanks man
Originally posted by: David Bishop
I'm trying to port a Delphi/Pascal ap to C#, and I can't seem to make sence of it.
Graphics g = Graphics.FromHdc(GetDesktopHandle());
g.DrawRectangle(new Pen(Color.Red, 3), 0, 0, 200, 100);
to draw a red box on the screen?
(I'm guessing a "Graphics" object is similar to the TCanvas object available in Delphi).
What am I missing?
Dave
How can I paint directly onto the windows desktop?
Shouldn't this put the desktop handle into the Graphics object?
And, shouldn't I be able to use:
Originally posted by: tomw
hi, I used this in a UserControl for a pretty high intensive gfx app (an oscillascope - yes, I know...) anyway... I was getting bizzare 'object in use elsewhere errors' until I realised that if you get a hdc using these classes you MUST place a monitor lock onto it until you're finished otherwise any old random windows-ism can frick with your device contect. FYI..
btw, nice code otherwise!
ReplyOriginally posted by: Tim Beauchamp
It works as expected if it the form it is on is activated and it is not
Ideally, what I would like to do is to capture it in a hidden window and
I am perplexed.
Below is a code sample.
Thanks in advance for insight into this problem
Tim Beauchamp
Graphics grContainer = axWebBrowser.CreateGraphics();
try
Graphics grImage = Graphics.FromImage(image);
IntPtr hdcContainer = grContainer.GetHdc( );
grContainer.ReleaseHdc( hdcContainer );
}
I have inconsistent results getting an image from an AxWebBrowser control.
covered by any
other form or control, but if I have another control over the top of it or
if another application
is covering it, it captures the front forms or windows. If it is half off
screen, half of the
image is missing.
show the image
in another control that can be scaled and manipulated.
Sr. Software Developer
Iteration Software, Inc.
/// <summary>
/// method CaptureBrowserImage
/// </summary>
private Image CaptureBrowserImage()
{
Image image;
{
image = new Bitmap( axWebBrowser.ClientRectangle.Width,
axWebBrowser.ClientRectangle.Height, grContainer );
}
catch
{
return null;
}
IntPtr hdcImage = grImage.GetHdc( );
BitBlt( hdcImage, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height,
hdcContainer, 0, 0, 13369376);
grImage.ReleaseHdc(hdcImage);
return image;
Originally posted by: Jason Arnold
I am trying to emulate the way windows drags a window using only the border. I have tried all kinds of stuff, one of which actually works. (Using 4 forms declared in the class and moving them around with the mouse events) But that is slow an painful to watch the flicker. Is there any way to just draw all over the screen, and not be limited to the form?
-Jason
Originally posted by: Angus Graham
You can make your blit much faster by constructing the offscreen in the resolution as the screen:
In your code just change the line
offScreenBmp = new Bitmap(this.Width, this.Height);
to
offScreenBmp = new Bitmap(this.Width, this.Height, this.CreateGraphics());
I got a 100% speed increase from doing this.
Reply