By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

BackgroundImage: Slow Redraw for runtime loaded bitmaps

P: n/a
I have an application which configures the user interface (UI) at
runtime, meaning, the images that make up the UI are loaded based on
the current configuration when the application starts. The UI is
populated with normal controls (buttons, lists, etc.) but some controls
can load a bitmap to represent them. For instance, each button in the
window loads a bitmap as it's BackgroundImage. Also, the
BackgroundImage of each dialog is also specified so as to embed an
image as the background for the dialog. I am loading the bitmaps at
startup as follows:

this.BackgroundImage = new Bitmap(imagefile); // a
System.Windows.Forms.Form
or
this.mybutton.BackgroundImage = new Bitmap(imagefile); // a button

My problem comes when the screen is refreshed. For instance, when I
open a new dialog and then close it and return to the main window, the
main window refreshes very slowly. I am not overriding the Paint
method in the main window. The machine is also not underpowered as it
is a 3.2Ghz with 2GB of memory. The images themselves are either BMP
or GIF files and they are not large (e.g. my 800x600 window background
image is 1,407KB in BMP format and 21KB in GIF). Each window only
contains a few (~10) controls and the typical button file size is
around 3KB for the GIF files. The images are also not reloaded each
time a new dialog is opened; they are loaded only at startup.

Can someone help me improve the refresh performance under these
circumstances?

Thanks!

Nov 30 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
raj
The problem may be that you are reloading the bitmap each time
i.e. if you have a constructor that draws the bitmap on a control
and the constructor loads them image
then everytime there is a refresh to window the control will be redrawn thus
it will call the constuctor and the constructor will reload the bitmap.

i would suggest you load the bitmaps to an array at the very first run and
save
them.

i have done this in the past

//private variable
ArrayList myList = new ArrayList();

string[] myBitmaps = new string[ {" path1.bmp", "path2.bmp"}

somefunction()
{
Bitmap b = null;
foreach(string s in myBitmaps)
{

b = new Bitmap.FromFile(s);
myList.Add(b);
}

to assign a bitmap

mypicbox.Bitmap = (Bitmap)myList[0];
hth

"jgraham" <ja***@rii.ricoh.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have an application which configures the user interface (UI) at
runtime, meaning, the images that make up the UI are loaded based on
the current configuration when the application starts. The UI is
populated with normal controls (buttons, lists, etc.) but some controls
can load a bitmap to represent them. For instance, each button in the
window loads a bitmap as it's BackgroundImage. Also, the
BackgroundImage of each dialog is also specified so as to embed an
image as the background for the dialog. I am loading the bitmaps at
startup as follows:

this.BackgroundImage = new Bitmap(imagefile); // a
System.Windows.Forms.Form
or
this.mybutton.BackgroundImage = new Bitmap(imagefile); // a button

My problem comes when the screen is refreshed. For instance, when I
open a new dialog and then close it and return to the main window, the
main window refreshes very slowly. I am not overriding the Paint
method in the main window. The machine is also not underpowered as it
is a 3.2Ghz with 2GB of memory. The images themselves are either BMP
or GIF files and they are not large (e.g. my 800x600 window background
image is 1,407KB in BMP format and 21KB in GIF). Each window only
contains a few (~10) controls and the typical button file size is
around 3KB for the GIF files. The images are also not reloaded each
time a new dialog is opened; they are loaded only at startup.

Can someone help me improve the refresh performance under these
circumstances?

Thanks!

Nov 30 '05 #2

P: n/a

raj wrote:
The problem may be that you are reloading the bitmap each time
i.e. if you have a constructor that draws the bitmap on a control
and the constructor loads them image
then everytime there is a refresh to window the control will be redrawn thus
it will call the constuctor and the constructor will reload the bitmap.

i would suggest you load the bitmaps to an array at the very first run and
save
them.


thanks for the response. however, i'm a bit confused (and i'm also new
to c# so maybe that helps explain why). i load the bitmaps in the
InitializeComponent() method which i assume is only run once, at
startup or when the object is instanciated. i understand the example
you provided, i just do not see how it differs from performing the
bitmap load when each control is created (which i assume is a one time
deal). Or, am i missing something?

jamey

Dec 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.