【发布时间】:2021-09-28 00:28:21
【问题描述】:
插入到 Catia V5 CATDrawing 文档时,.png 图像的透明度出现问题。使用System.Drawing.Image.Save() 保存后,图像发生了一些变化。如果使用 Paint.NET 打开新保存的图像,图像是透明的,一切看起来都很好,但是当插入到CATDrawing 中时,图像没有透明度。我无法找出图像中导致透明度损失的变化。
我正在旋转图像,这就是我需要保存它的原因。这是我用来旋转和保存图像的代码。
Bitmap image1 = (Bitmap)Image.FromFile(sImagePath1, true);
image1.RotateFlip(RotateFlipType.Rotate90FlipNone);
image1.MakeTransparent();
image1.Save(sImagePath2, ImageFormat.Png);
我也尝试过使用 NuGet 包 Magick.NET-Q16-AnyCPU 失败
using (MagickImage mimg = new(sImagePath1))
{
mimg.Rotate(90);
mimg.Write(sImagePath2);
}
并保存为流
Bitmap image1 = (Bitmap)Image.FromFile(sImagePath1, true);
image1.RotateFlip(RotateFlipType.Rotate90FlipNone);
using (FileStream outputFileStream = new(sImagePath2, FileMode.Create))
{
var stream = new MemoryStream();
image1.Save(stream, ImageFormat.Png);
stream.Position = 0;
stream.CopyTo(outputFileStream);
}
问题:有没有其他通过C#代码旋转和保存图片的解决方案?
【问题讨论】: