我有一个.net core 2应用程序。我使用syncfusion,docIO库来处理word文档。 我有一个word文档,我想将文档中所有图像的格式更改为.png
我发现WPicture对象遍历段落:
if (paragraphItem is WPicture)
{
var wpicture = paragraphItem as WPicture;
var imageBytes = wpicture.ImageBytes;
}
如何更改WPicture对象的格式?
答案 0 :(得分:0)
Essential DocIO没有直接的API来更改图像格式。由于System.Drawing命名空间在ASP.NET Core平台中不可用,因此您需要使用任何一个备用图像处理库(如MSDN中所述)来更改图片的图像格式。
这里,下面的示例代码使用CoreCompat帮助程序库来更改图像格式:
WPicture picture = item as WPicture;
//Load the DocIO WPicture image bytes into CoreCompat Image instance.
Image image = Image.FromStream(new MemoryStream(picture.ImageBytes));
//Check image format, if format is other than png then convert the image as png format.
if (!image.RawFormat.Equals(ImageFormat.Png))
{
MemoryStream imageStream = new MemoryStream();
image.Save(imageStream, ImageFormat.Png);
//Load the png format image into DocIO WPicture instance.
picture.LoadImage(imageStream);
imageStream.Dispose();
}
//Resize the picture width and height.
picture.Width = 400;
picture.Height = 400;