3

我有这段代码可以在 C# Windows 窗体应用程序的 if 循环中旋转图像,但窗体在窗体输出中不显示任何内容。

任何人都可以帮忙吗?

this.splitContainer1.Panel2.Controls.Add(PictureBox1);
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
PictureBox1.Image = bitmap; //Image.FromFile(@"C:\image.jpg");
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
PictureBox1.Image = (Image)(RotateImg(bitmap, 30.0f, Color.Transparent));
4

2 回答 2

5

if you need to rotate an image on common angles you can use RotateFlip method with ease. Please see my sample code:

string fileName = "somefile.png";
System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Png;
Bitmap bitmap =(Bitmap)Bitmap.FromFile(fileName );
//this will rotate image to the left...
bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
//lets save result back to file...
bitmap.Save(fileName, imageFormat);
bitmap.Dispose();

That's all, hope it helps.

于 2012-06-13T08:51:24.453 回答
4

尝试这个:

PictureBox1.Images.RotateFlip(RotateFlipType.Rotate180FlipX);
PictureBox1.Refresh();
于 2016-04-27T10:28:04.273 回答