473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[GDI] DrawImage unexpectedly slow

I'm writing a fairly simple two-player puzzle game. I have a background
image in a PNG file (44 KB, 160 x 320 pixels) which I load into an Image
object ...

imgCachedBackgr ound = Image.FromFile( strImageFilenam e); // a PNG file

The Image is then painted onto two PictureBoxes several times a second ...

Graphics g = e.Graphics;
g.DrawImageUnsc aled(imgCachedB ackground, 0, 0);

I have provided the option of playing at double size (so that the
PictureBox, background, etc. double up to 320 x 640 pixels). Rather than
scaling the image in each Paint event, I store and use a double-size image,
like this.

imgCachedBackgr ound = Image.FromFile( strImageFilenam e); // a PNG file

if (iSizeRatio > 1) // i.e. 2 for double size
{
imgCachedBackgr ound = new Bitmap(
imgCachedBackgr ound, new Size(
iSizeRatio * imgCachedBackgr ound.Width,
iSizeRatio * imgCachedBackgr ound.Height));
}

(The image is only cached once, not in every Paint event!)

The speed is fine for two players at single size and for one player at
double size, but when both PictureBoxes are at double size there is a major
drop in speed.

Can anyone explain this or suggest how I might do it more efficiently?

P.

--
www.CL4.org
Nov 15 '05 #1
1 8972
Well Formed this month has an article on writing Windows Forms controls
using DirextX.

I think you'd get great performance if you did the blitting using DirectDraw
through the managed wrappers. GDI+ is notoriously slow, especially if you're
thinking of doing any sizable blitting more than about 5 times a second.

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

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

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

Blog http://bobpowelldotnet.blogspot.com

"Paul E Collins" <fi************ ******@CL4.org> wrote in message
news:bm******** *@hercules.btin ternet.com...
I'm writing a fairly simple two-player puzzle game. I have a background
image in a PNG file (44 KB, 160 x 320 pixels) which I load into an Image
object ...

imgCachedBackgr ound = Image.FromFile( strImageFilenam e); // a PNG file

The Image is then painted onto two PictureBoxes several times a second ...

Graphics g = e.Graphics;
g.DrawImageUnsc aled(imgCachedB ackground, 0, 0);

I have provided the option of playing at double size (so that the
PictureBox, background, etc. double up to 320 x 640 pixels). Rather than
scaling the image in each Paint event, I store and use a double-size image, like this.

imgCachedBackgr ound = Image.FromFile( strImageFilenam e); // a PNG file

if (iSizeRatio > 1) // i.e. 2 for double size
{
imgCachedBackgr ound = new Bitmap(
imgCachedBackgr ound, new Size(
iSizeRatio * imgCachedBackgr ound.Width,
iSizeRatio * imgCachedBackgr ound.Height));
}

(The image is only cached once, not in every Paint event!)

The speed is fine for two players at single size and for one player at
double size, but when both PictureBoxes are at double size there is a major drop in speed.

Can anyone explain this or suggest how I might do it more efficiently?

P.

--
www.CL4.org

Nov 15 '05 #2

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

Similar topics

1
3853
by: Vicente Nicolau | last post by:
hello, I have a problem when I preview or print a document in an ISO A0. I have an application which load an 10x10 image (bmp or jpg) and spread it in the A0 paper. When I make the print preview, it starts to draw (ev.Graphics.DrawImage) but after a few seconds an exception throws:
1
10078
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 use this code, but it does not work (it draws only black). What am I missing ?! public int LoadImage (string strFileName) { // load bitmap
5
4129
by: anonymous | last post by:
I'm writing a program that deals extensively with the printer. For the most part my application runs fine, but occasionally I run into some Exceptions. The most common exceptions I run into are NullReferenceException and InvalidOperationException : The object is currently in use elsewhere. Unfortunately this appears to be a race condition. ...
7
3215
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image is drawn by loading a jpg into a bitmap and then setting picturebox.image = mybitmap. Ive created my own class, inheriting from the picturebox and...
4
1163
by: J | last post by:
I am a newbie in vb.net and gdi+, in my windows app, I using System.drawing to display image file, now when user view a multipage tiff file, they moved to 3rd page, then chose a new tiff file, it's display 3rd page instead of first page, I tried something but not works, so what I need to do? please help. Thank in advance.
15
5311
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run...
4
2548
by: John Swan | last post by:
Hello. I'm trying to create a simple program that amongst other things creates a thumbnail of an image (Bitmap) to a set size determined by the user in pixels? The problem is: All of the examples I have seen so far are in c#. Can anyone please provide reference to a c++ managed version. Thanks. John
0
1376
by: Fromethius | last post by:
Hello everyone and thank you for taking the time to read my post I am running Visual C++ 2005 and I'm having some trouble with GDI+. I have two bitmaps: Bitmap* pngFrame; Bitmap* pngEmblem;
0
1599
by: johot | last post by:
I am currently creating a little photo application. In this application the user is able to zoom in the image and after zooming panning around inside the zoomed image with the mouse. The strange thing is that the first zoom is really slow, and so is the first panning. So if you zoom into an image it will first take some time, and when trying to...
0
7815
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7433
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7763
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1891
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
712
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.