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 2108
I've worked on this some more but have not found a solution. No ideas from anyone?
RedSon 5,000
Recognized Expert Expert
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 I make a button with the same, after the click
it paints it, why the problem, i can't get out of it.........
|
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 Invalidate(Rectangle))
flickers in a nasty way when repainting.
This does not happen in the Solitare (PC + WinCe) Versions a well as in a
Card game where I have the C++ Source.
The use of an empty OnPaintBackground brings no visable results.
|
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 image at 1:2 zoom i have the following
xScaleFactor = 0.5
yScaleFactor = 0.5
public static Bitmap ScaleBitmap(Bitmap inputBmp, double xScaleFactor,
double yScaleFactor) {
//Create a new bitmap object based on the input
|
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 make some interesting apps which could tranform images
(i.e. making saturation of colours "heavy", or gradually fade to grayscale,
or "erasing" a colour... and so on), while nowadays it seems quite impossible.
Now that I got .NET over...
| |
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 passed.
I'm struggling with making the delegate/invoke thing work, as I know
GUI objects aren't thread-safe. I don't quite understand the concept
I'm supposed to use to modify the GUI thread-safe.
Below is my form and my Circle class. Currently,...
|
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() From the Standard CreateGraphics() function the code
below works
|
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 screen and sometimes, i get a frame or two of just blank jframe color
public void draw()
{
BufferStrategy bf = this.getBufferStrategy();
Graphics2D g = null;
if(scrollPos>lastCoveredPos) lastCoveredPos =...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |