问题很简单,引用的图像库出问题了,我使用的centos stream 8,.net 8的框架,引用的图像库是System.Drawing.Common
Image sourceImage = Image.FromFile(sourcePath) using (Bitmap newImage = new Bitmap(900, 383)) { using (Graphics graphics = Graphics.FromImage(newImage)) { graphics.DrawImage(sourceImage, 0, 0, 900, 383); } newImage.Save(destinationPath, System.Drawing.Imaging.ImageFormat.Jpeg); // 可以根据实际情况修改保存格式 }
后面不用使用这个
dotnet add package SixLabors.ImageSharp dotnet add package SixLabors.ImageSharp.Drawing
// 新的宽度和高度 int newWidth = 800; int newHeight = 600; using (Image<Rgba32> image = SixLabors.ImageSharp.Image.Load<Rgba32>(sourcePath)) { // 缩放图片 image.Mutate(x => x.Resize(newWidth, newHeight)); // 保存缩放后的图片 image.Save(destinationPath); }
皆可解决,中间把服务器重装了好多遍都解决不了但是换一种方式即可
标签:exception,using,Image,initializer,newImage,linxu,SixLabors,image,Drawing From: https://www.cnblogs.com/axyls/p/18286863