How is the Bitmap.DrawImage with opacity implemented?
When I run the code below it takes a long time per iteration where:
aux.DrawImage(0, 0, oldStyleImage, 0, 0, DesktopManager.ScreenWidth, DesktopManager.ScreenHeight);
takes 11 ms
aux.DrawImage(0, 0, _currentDesktop._screenBuffer, 0, 0, DesktopManager.ScreenWidth, DesktopManager.ScreenHeight, i);
takes 400-411 ms !!!
aux.Flush();
takes 9-10 ms
(the measurements are in Debug mode)
const int fadeStep = 14;
const int fadeSleep = 3;
const int fadeMaxOpacity = 256;
Bitmap aux = new Bitmap(DesktopManager.ScreenWidth, DesktopManager.ScreenHeight);
for (ushort i = 1; i <= fadeMaxOpacity; i += fadeStep)
{
aux.DrawImage(0, 0, oldStyleImage, 0, 0, DesktopManager.ScreenWidth, DesktopManager.ScreenHeight);
aux.DrawImage(0, 0, _currentDesktop._screenBuffer, 0, 0, DesktopManager.ScreenWidth, DesktopManager.ScreenHeight, i);
aux.Flush();
Thread.Sleep(fadeSleep);
}
aux.Dispose();
oldStyleImage.Dispose();
aux = oldStyleImage = null;