471,354 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

BackgroundImage: Slow Redraw for runtime loaded bitmaps

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
2 5153
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

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.

Similar topics

1 post views Thread by Ray Mitchell | last post: by
1 post views Thread by James Dean | last post: by
reply views Thread by Jan Bockler | last post: by
1 post views Thread by moi.romanowsky | last post: by
2 posts views Thread by =?Utf-8?B?UmFodnlu?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.