DirectDraw replacing e.Graphics.DrawImage?

andolsson

Newcomer
Joined
Feb 24, 2004
Messages
1
Hi,

I am constructing a usercontrol that displays a zoomed part of an image. The user can grab the image and zoom to different parts, Adobe Acrobat-style.

I call e.Graphics.DrawImage, in OnPaint(e), to draw the zoomed piece of the bitmap onto the control. This is currently the bottleneck of my app.

I am experimenting with letting DirectDraw to the blitting instead, but cannot get it to work fast enough without flickering - it seems that the built-in double buffering for Surfaces in DirectDraw is only available in full-screen mode.

Does anyone know of a way to circumvent/fix this? I've tried

public void Draw(Graphics g, Rectangle sourceRect)
{
System.IntPtr ptrHdc = g.GetHdc();
_surfaceBitmap.DrawToDc(ptrHdc, this.ClientRectangle, sourceRect);
g.ReleaseHdc(ptrHdc);
}

and enabling the DoubleBuffering Style for the control. This works and does not produce any flicker, but results in compression artifacts in the image when zooming out beyond a certain level, and is really not faster than e.Graphics.DrawImage at all!

Any tips or tricks?

Regards

AndreasO
 
Hi,

The double/triple buffer on the surfaces can work on a windowed mode as well, maybe there is a problem with the bit depth that you are using, it happened to me before.

Other tip: How often are you flipping? if you flip on an unlimited loop it will also consume all your machine resources, maybe your kind of app doesn't need a very high frame rate. (this usually happens on the windowed mode)

Another way to do it, try the Sprite object of the Direct3D (instead of using DirectDraw) is very fast and you don't have to bother about 3D parameters, just put the Z on the vector as 0.

_MainSprite.Begin (SpriteFlags.AlphaBlend);

m_MainSprite.Draw (
Texture,
Rectangle_of_your_texture,
VectorNull,
VectorPosition on the screen,
Color.FromArgb(255,255,255,255).ToArgb() );

m_MainSprite.End();

The texture is your image or whatever you want to blit.

Hope this is helpful,
Regards
Salvador
 
Back
Top