S
Hi,
ich benutze eine Paintbox mit GDI+. Ich will jetzt, dass wenn man die Maus mit gedrückter maustaste linien auf die Paintbox zeichnet. Dann wird PaintBox->Refresh() aufgerufen. Problem: Es ensteht ungeheures flimmern. Bildgröße: 800x600
Das Programm könnt ihr selber testen und von http://www.virtualuna.de/giveme/Project1.exe runterladen. Nur 33kb groß. Bräuchtet aber WinXP wegen der GDI+.DLL.
Code:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
delete myPen;
delete Bmp;
Gdiplus::GdiplusShutdown(gdiplusToken);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
Gdiplus::Graphics gfx(Bmp);
if(mdown)
{
//Bmp->SetPixel(X, Y, Color::Blue);
gfx.DrawLine(myPen, X1, Y1, X, Y);
PaintBox1->Repaint();
}
X1 = X;
Y1 = Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
mdown = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
mdown = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
myPen = new Gdiplus::Pen(Color::Blue, 1);
Bmp = new Gdiplus::Bitmap(640,480, PixelFormat32bppARGB);
Gdiplus::Graphics gfx(Bmp);
gfx.Clear(Color::White);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
Gdiplus::Graphics gfx(PaintBox1->Canvas->Handle);
gfx.DrawImage(Bmp, 0,0);
}
//---------------------------------------------------------------------------
Vielen dank schonmal