Click here to Skip to main content
15,916,951 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello, I am using a transparent PNG graphic on a user control.

Several controls (100x100px) makes a slow display of complete form and disturbs users.

Is there a mechanism to make it faster? for example when at the first drawing of control, save the final image as Bitmap, then do not try to paint all graphics having transparency everytime when painting required. Somehow caching mechanism.

Thank in advance for your ideas.

The code is simple, you are just overriding the OnPaint, and drawing some image and text. The image has transparency and this makes slower UI when the program run on a relatively slower machine. But I certainly need transparency.

C#
protected override void OnPaint(PaintEventArgs e)
{
    g.DrawImage(this.Image, r, 0, 0, this.Image.Width, this.Image.Height, GraphicsUnit.Pixel);
    g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), r, sf);
}
Posted
Updated 8-Dec-10 8:51am
v3

Don't over-think this.

All graphics are transformed to bitmaps when they are decompressed as compressed images can't be rendered to the screen. You may have compressed graphics as textures, which means that the resources will be in the video card memory and will not affect performance (true of some UI paradigms). There are 2D and 3D frameworks that support video card acceleration to varying levels of degrees.

"Several" controls - under 100, for certain - won't affect performance on any reasonably modern machine.

If you're really running into a real-life issue here, try to make sure you're not loading 5MP images onto buttons, i.e., if you have a button that is 60x60, make your images 60x60.

Finally, if the case that you do have more than 100 unique UI elements on a screen, I will go out on a limb and suggest that it's not the speed of the graphics that the users are going to complain about.

Cheers.
 
Share this answer
 
How do you render the image? If you would for example load each image from file in the paint event it is very clear that this is going to be a problem.

Maybe you could update the question with some code that is relevant to rendering the images so I (and others) can have a look.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900