问题描述
在插入 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# 代码旋转和保存图像?