Main Site Documentation

Drawing image with opacity


#1

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;

#2

I made an assembly function that would do the drawing with opacity but can’t get it fast enough.
I still have 26 instructions that would need to execute 130560 times. Estimating a mean of 3 clocks ( ??? ) per instruction, it would still take more than 100 ms without the flushing for the entire screen. So, not enough power… I’ll have to drop this.

An integrated GPU would be cool 8)


#3

FEZ Hydra will give you 6 times the speed.


#4

Yeah… I know ;D
But this one is on EMX.