Hallo,
ich habe eine Panel so erweitert, das ich ein darin enthaltenes Bild um einen bestimmten Winkel drehen kann. Dazu speicher ich das eingestellte Hintergrundbild in einer lokalen Variable originalBitmap und überschreibe die OnPaint-Methode.
So lange ich den Winkel fest vorgebe ist alles in Ordnung.
Wenn ich den Winkel ändere bleibt aber das alte Bild stehen und das neue wird darüber gezeichnet.
Wie kann ich das verhindern ?
Hier mal der Code
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected override void InitLayout()
{
originalBitmap = (Bitmap)this.BackgroundImage;
base.InitLayout();
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// Don't paint background
}
protected override void OnPaint(PaintEventArgs pe)
{
if (originalBitmap != null)
{
this.Size = new Size(originalBitmap.Height + originalBitmap.Width, originalBitmap.Height + originalBitmap.Width);
Image image = originalBitmap;
int heightOffset = originalBitmap.Width;
double rotationRad = (rotation / 180) * Math.PI;
Point[] destinationPoints = {
new Point(0 , heightOffset), // destination for upper-left point of
// original
new Point(Convert.ToInt16(Math.Cos(rotationRad) * image.Width) ,
heightOffset - Convert.ToInt16(Math.Sin(rotationRad) * image.Width)), // destination for upper-right point of
// original
new Point(Convert.ToInt16(Math.Sin(rotationRad) * image.Height),
heightOffset + Convert.ToInt16(Math.Cos(rotationRad) * image.Height))
};
pe.Graphics.CopyFromScreen(10, 10, 0, 0, new Size(100, 100));
pe.Graphics.DrawImage(image, destinationPoints);
}
base.OnPaint(pe);
}
Ich beschütze das was am Wichtigsten ist!
Hallo d.gierse,
Wenn ich den Winkel ändere bleibt aber das alte Bild stehen und das neue wird darüber gezeichnet.
ich würde mal sagen, das liegt an:
protected override void OnPaintBackground(PaintEventArgs pevent) { // Don't paint background }
herbivore