I am attempting to create a program in C# which part of it consists of one image fading to another. The best way I found this to work is from an example by Bob Powell on the thread http://www.thescripts.com/forum/thread106125.html.
The issue is the performance of this code. A simple program that fades two images at 1280x1024 takes ~100% CPU. This is of course an issue. I'm hoping to see if anyone has a suggestion on how to accomplish this in a much more efficient manner. The code I am using is below,
The class: -
public class FadePanel : Control
-
{
-
-
Image _imageA;
-
-
public Image ImageA
-
{
-
get { return _imageA; }
-
set { _imageA = value; }
-
}
-
-
Image _imageB;
-
-
public Image ImageB
-
{
-
get { return _imageB; }
-
set { _imageB = value; }
-
}
-
-
int _fade = 0;
-
float _fadeTime;
-
-
public float FadeTime
-
{
-
get { return _fadeTime; }
-
set { _fadeTime = value; }
-
}
-
-
Timer t = new Timer();
-
-
public FadePanel()
-
{
-
-
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
-
ControlStyles.DoubleBuffer, true);
-
-
t.Tick += new EventHandler(t_Tick);
-
-
}
-
-
protected override void OnPaint(PaintEventArgs e)
-
{
-
if (_imageA == null)
-
return;
-
-
e.Graphics.DrawImage(_imageA, this.ClientRectangle, 0, 0, _imageA.Width,
-
_imageA.Height, GraphicsUnit.Pixel);
-
-
if (_imageB == null)
-
return;
-
-
ImageAttributes ia = new ImageAttributes();
-
-
ColorMatrix cm = new ColorMatrix();
-
-
cm.Matrix33 = 1.0f / 255 * _fade;
-
-
ia.SetColorMatrix(cm);
-
-
e.Graphics.DrawImage(_imageB, this.ClientRectangle, 0, 0, _imageA.Width,
-
_imageA.Height, GraphicsUnit.Pixel, ia);
-
-
//base.OnPaint(e);
-
}
-
-
public void Fade()
-
{
-
_fade = 1;
-
this.t.Interval = (int)(1000f * _fadeTime / 32);
-
this.t.Enabled = true;
-
}
-
-
private void t_Tick(object sender, EventArgs e)
-
{
-
_fade += 8;
-
if (_fade >= 255)
-
{
-
_fade = 255;
-
t.Enabled = false;
-
}
-
Invalidate();
-
}
-
-
protected override void OnPaintBackground(PaintEventArgs pevent)
-
{
-
-
}
-
}
-
The form is of proper size for the images and this is the constructor for the form. -
public Form1()
-
{
-
InitializeComponent();
-
-
fpPictureBox.ImageA = Image.FromFile(@"images\forest01.jpg");
-
fpPictureBox.ImageB = Image.FromFile(@"images\winter01.jpg");
-
fpPictureBox.Fade();
-
}
-
Any help is appreciated.
2 2078
I've worked on this some more but have not found a solution. No ideas from anyone?
You can try setting the thread priority level of your processes worker thread to a lower level.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jeroen Ceuppens |
last post by:
Hi,
When i do this in my programma, in the contstructor of the form:
g.DrawImage(i,new
Rectangle(0,0,i.Width,i.Height),0,0,i.Width,i.Height,GraphicsUnit.Pixel);
it doens't paint it ;( but if...
|
by: Mark Johnson |
last post by:
Using: VS 2003 NET C# for Framework and Framework Compact
Trying : Moving a Card (Bitmap) as in Solitare (PC + WinCe) Version on
OnMouseMove
Problem : The affected drawing Area by Invalidate (or...
|
by: James Dean |
last post by:
I have tried a few different methods for scaling an image down but all
seem a bit on the slow side. Is there any way i can make this scaling
faster.......
Here is how i do it now.
To display my...
|
by: Darren Clark |
last post by:
I am trying to simply embed a opaque image over another image...
if i use a windows form it works..
e.g.
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
|
by: Tamer Abdalla via DotNetMonster.com |
last post by:
Hello, everyone!
I DO need some help in order to understand how to create graphics in VB.NET.
I'm a little bit confused... I once knew a time when using Point & PSet was
almost the only way to...
|
by: perspolis |
last post by:
Hi all
is it possible in C# to copy content of a graphics object to another like
BitBlt API??
thanks
|
by: koschwitz |
last post by:
Hi,
I hope you guys can help me make this simple application work. I'm
trying to create a form displaying 3 circles, which independently
change colors 3 times after a random time period has...
|
by: DaveL |
last post by:
hello
I have a Bit map 1367 wide 32 high
this bitmap contains like 40 separate Images
32x32
I tell it the id*32 to get the approiate Image from
the source Bitmap
When i CreateGraphics()...
|
by: drsmooth |
last post by:
Hi, i have made several different things using a double buffer and a jframe before but never had this problem:
if you look thrugh the code, you can see that i draw a whole bunch of stuff to the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
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...
| |