picShowPDF.Image = Image.FromFile(pathFile);C#怎么把这个图片怎么旋转90°
时间: 2024-09-13 14:08:44 浏览: 46
要旋转图片90度,你可以使用C#中的Graphics类,具体步骤如下:
1. **读取原始图片**[^1]:
```csharp
string pathFile = "path_to_your_image.jpg";
Image originalImage = Image.FromFile(pathFile);
```
2. **创建一个新的Bitmap来保存旋转后的图像**:
```csharp
Bitmap rotatedImage = new Bitmap(originalImage.Width, originalImage.Height);
Graphics graphics = Graphics.FromImage(rotatedImage);
```
3. **设置旋转角度并应用到新的Bitmap上**:
```csharp
graphics.RotateFlip(RotateFlipType.Rotate180FlipNone, originalImage.Width / 2, originalImage.Height / 2);
graphics.DrawImage(originalImage, 0, 0);
```
4. **将旋转后的Bitmap赋值给picShowPDF.Image**:
```csharp
picShowPDF.Image = rotatedImage;
```
完整示例代码:
```csharp
private void RotateAndDisplayImage(string pathFile)
{
// Step 1: Read original image
Image originalImage = Image.FromFile(pathFile);
// Step 2: Create a new bitmap to hold the rotated image
Bitmap rotatedImage = new Bitmap(originalImage.Width, originalImage.Height);
Graphics graphics = Graphics.FromImage(rotatedImage);
// Step 3: Rotate and flip the image
graphics.RotateFlip(RotateFlipType.Rotate180FlipNone, originalImage.Width / 2, originalImage.Height / 2);
graphics.DrawImage(originalImage, 0, 0);
// Step 4: Assign the rotated image to picShowPDF.Image
picShowPDF.Image = rotatedImage;
}
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)