Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How winform makes picturebox rotate
How winform makes picturebox rotate
//You can rotate at any angle, and you can choose the fill color for the corner blank that appears during rotation.

Use the system;

Use the system. Drawing;

Use the system. Drawing . Drawing2D

Use the system. Drawing. Imaging;

Use the system. Text;

Use the system. Windows . Forms

Namespace bitmaprerote

{

Public partial classes Form 1: Form

{

Public Form 1 ()

{

initialize component();

}

Public static bitmap KiRotate (bitmap bmp, floating angle, color bkColor)

{

int w = bmp。 Width+2;

int h = bmp。 Height+2;

Pixel format PF;

if (bkColor == Color。 Transparent)

{

Pf = pixel format. Format32bppArgb

}

other

{

pf = bmp。 Pixel format;

}

Bitmap tmp = new bitmap (w, h, pf);

Graph g = graph. from image(tmp);

g.clear(bk color);

g.DrawImageUnscaled(bmp, 1, 1);

g.dispose();

graphics path path = new graphics path();

Path. AddRectangle(new RectangleF(0f,0f,w,h));

Matrix mtrx = new matrix ();

mtrx。 Rotation (angle);

RectangleF rct = path。 get bounds(mtrx);

Bitmap dst = new bitmap ((int)rct. Width, (internal) rct. Height, pf);

G = graph. from image(dst);

g.clear(bk color);

g.TranslateTransformx,-rct。 y);

G. rotation transformation (angle);

G. interpolation mode = interpolation mode. High quality bilinear;

g.DrawImageUnscaled(tmp,0,0);

g.dispose();

tmp。 dispose();

Return to dst

}

Private void button2_Click (object sender, EventArgs e)

{

Bitmap = new bitmap ("f: \ \ hj.jpg");

this.pictureBox 1。 SizeMode = PictureBoxSizeMode。 StretchImage

Map = KiRotate(map, 30, color. Pink);

pictureBox 1。 Image = map;

}

}

}