"продвинутое рисование на форме"

Средства разработки, технические вопросы, отвечает (по мере сил) Отдел Разработок
apachik
Студент (1 lvl)
Сообщения: 25
Зарегистрирован: Сб фев 18, 2006 20:57

Сообщение apachik » Чт апр 13, 2006 18:14

sshd писал(а):
apachik писал(а):работает :D . только вот DrawImage тормозит. можно побыстрее сделать?
можно.
использовать native code.
не понял. что значит native code?
предлагаешь отказаться от .НЕТ?

apachik
Студент (1 lvl)
Сообщения: 25
Зарегистрирован: Сб фев 18, 2006 20:57

Сообщение apachik » Чт апр 13, 2006 18:27

вот еще что нашел:
http://www.codeproject.com/cs/media/fli ... rawing.asp
Introduction
This article describes how to implement flicker free drawing on Windows Forms using GDI+, it assumes you have a basic understanding or VS.NET, C# and the .NET framework.

Background
Flicker free drawing or double buffering is a well know technique used in the Windows programming world to reduce flicker when handling paint events in a window.

Normally a generic window programs draw directly to the device context (Graphics Object) when a WM_PAINT (Paint) event occurs. This can lead to flickering if the window is refreshed (Invalidated) repeatedly. Three examples where flickering happen would be during a Window resize or animation (a timer is fired and in the timer event the window is refreshed) or when a object is dragged over the window (e.g. Visio)

We can eliminate flickering using a technique known as double buffering. Rather than drawing directly on the graphics object, we draw to an off screen graphics object and when the drawing is complete we draw the off screen graphics object onto the graphics object supplied by the Paint event. We also override the OnPaintBackground method to prevent the windows form performing any background rendering (we must paint the background ourselves during the rendering in the off screen graphics object, this is usually the first thing that is done).

The double buffering technique is encapsulated in a simple class called DBGraphics and can be easily implemented in a typical windows form based application show below.

Using the code
The double buffering class can be used within the scope of the windows form. The steps below describe how to implement the DBGraphics class in your code:

Step 1 - Declare the DBGraphics variable in your windows form class and instantiate the object in the windows form constructor.

Код: Выделить всё

using GDIDB; // Declare the namespace
  
 public class MainWnd : System.Windows.Forms.Form
{
     ... Some other code
    private DBGraphics memGraphics;
     ... Some other code
      
    public MainWnd()
    {    
        memGraphics = new  DBGraphics();
    }           
     
}; 
 
Step 2 - Handle the resize and load event to create the double buffer object to the size of the Client Rectangle. This is done in form load event as the resize event only gets fire when the form is manually resized. One thing to note here is we need to obtain the graphics object of the form even though we are not in the Paint event, this done by calling this.CreateGraphics()is is similar to GetDC().

Код: Выделить всё

private void MainWnd_Load(object sender, System.EventArgs e)
{ 
<B>    memGraphics.CreateDoubleBuffer(this.CreateGraphics(), this.ClientRectangle.Width, this.ClientRectangle.Height);
</B>}                 
                      
private void MainWnd_Resize(object sender, System.EventArgs e)
{ 
<B>    memGraphics.CreateDoubleBuffer(this.CreateGraphics(), this.ClientRectangle.Width, this.ClientRectangle.Height);
</B>    Invalidate(); // Force a repaint after has been resized 
} 
Step 3 - Override the OnPaintBackground is to allow the paint event to render the background.

Код: Выделить всё

<B>protected override void OnPaintBackground(PaintEventArgs pevent)
{
}</B>
Step 4 - Finally implement the Paint event

Код: Выделить всё

protected override void Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

<B>    if (memGraphics.CanDoubleBuffer())
    {
    // Fill in Background (for effieciency only the area that has been clipped)
         memGraphics.g.FillRectangle(new SolidBrush(SystemColors.Window), e.ClipRectangle.X,e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);

        // Do our drawing using memGraphics.g instead e.Graphics
     
        ... Some other code
   
       // Render to the form
        memGraphics.Render(e.Graphics);
    }
</B>}


только вот с делкарацией GDIDB какие то непонятки

zobot
Кандидат (3 lvl)
Сообщения: 139
Зарегистрирован: Вт апр 26, 2005 13:39

Сообщение zobot » Вт апр 18, 2006 15:12

подскажите плиз как сделать синхронизацию по кадровой развёртке (аля как на больших кампиках синхронизация по регистру Vertical blanking видязи в досе и direct draw).

Чё-т не могу найтить...

Закрыто

Вернуться в «Программирование для КПК»