|
-
Mar 9th, 2003, 11:05 PM
#1
Thread Starter
Hyperactive Member
.NET's BUILT-IN DOUBLE BUFFERING and FASTER GRAPHICS DRAWING in GDI+
Alright, I've seen many examples from people all over the net trying to mimic double buffering by using Image/bitmap and graphics objects! However, all of those examples are VERY slow and inefficient!!!!!
Here's the absolute BEST way to do double buffering with the GDI+:
First, add the following 3 lines into your form's constructor (the New method, where it says "put initialization code here"):
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.UserPaint, True)
Now, draw all of your graphics in the Paint event. They will appear only after the Paint event terminates!
Finally, as I said, Image and Bitmap objects are slow. Their good for image manipulation, but definately NOT for speed. You'll be very lucky to render them at about 10 FPS (even with a fast computer), and it will take up all of your processing power and much of your RAM. If you need extra speed and more efficient use of system resources, create TextureBrush objects from your Image/Bitmap objects, and use those in your loops in place of the image and bitmap objects, or wherever you need the speed.
I havn't seen either of these tricks documented very well, and I've seen too many people make futile attempts to mimic them. I hope this helps you all out!
Last edited by Hu Flung Dung; Mar 9th, 2003 at 11:10 PM.
-
Mar 10th, 2003, 12:22 AM
#2
did you read that in c-sharpcorner?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Mar 10th, 2003, 01:58 AM
#3
Thread Starter
Hyperactive Member
Originally posted by MrPolite
did you read that in c-sharpcorner?
Umm, I've never even visited that site yet! This is all what I discovered by reading MSDN and doing some experimentation. This is mainly a response to the "back buffering" thread posted earlier.
EDIT:
Hey, that is a kewl site! I'll have to check it out more often!
Last edited by Hu Flung Dung; Mar 10th, 2003 at 02:01 AM.
-
Jul 25th, 2003, 03:55 PM
#4
Fanatic Member
wow!!
i know this is an older post, but i was searching around for double buffering information, and stumbled upon this post.. i thought it was gonna be a lot harder to implement double buffering.. but if .net does it built in, alright, that's awesome!!!
just wanted to thank you 'Hu Flung Dung' for posting this... i think it should be posted somewhere more prominent as well.. like submit it to pscode or something... it was a life-saver.. i had almost given up on writing my own control since it kept flickering...
anyways, thanks again
-
Jul 25th, 2003, 06:44 PM
#5
Thread Starter
Hyperactive Member
Your welcome!
I was developing a shoot'em up game using nothing but GDI+ for graphics. It's already playable and runs great, but it still needs real levels (I just have 1 test level now), a scrolling background, and a user-friendly interface. I havn't worked on it for about a month though, as I don't like working on one thing for very long. I always switch between several projects. Maybe I should go finnish it and post it on PSC!
Anyway, Mr. Polite said that technique is already mentioned on c-sharpcorner.com
-
Jul 26th, 2003, 11:39 PM
#6
Member
I can't seem to draw the TextureBrush correctly (using Graphics.FillRectangle()). When using it, it "wraps" the image as it moves.
Can you post a snippet of your code so we can see how you're using it?
-
Jul 29th, 2003, 03:03 AM
#7
Thread Starter
Hyperactive Member
Originally posted by wyrd
I can't seem to draw the TextureBrush correctly (using Graphics.FillRectangle()). When using it, it "wraps" the image as it moves.
Can you post a snippet of your code so we can see how you're using it?
Sorry for the late reply, been out for the past couple days.
You have to set the WarpMode property to Clamp
Also, keep in mind that it will GREATLY improve performance if the region you specify in FillRectange is the same size as the image represented by the TextureBrush object.
TextureBrush is a really cool class, which allows for easy image rotation, flipping, tiling, stretching, etc... Although MS could have provided better documentation about how to use it. (Oh, and keep in mind that you have to use the TranslateTransform method to move the image where you want. Look up on MSDN for details - this aspect is kinda weired)
Last edited by Hu Flung Dung; Jul 29th, 2003 at 03:07 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|