无法使用c#-版本1.0.0-Beta007中的SixLabors.ImageSharp处理.jpg图像
我无法使用c#中的SixLabors.ImageSharp版本-1.0.0-Beta007保存jpg图像,它抛出错误。 除了GIF、PNG、JPEG、BMP格式的图像之外,还有什么解决方案可以解决这个问题 引发异常: 无法加载图像。可用解码器:无法使用c#-版本1.0.0-Beta007中的SixLabors.ImageSharp处理.jpg图像,c#,image,asp.net-core,aws-lambda,imagesharp,C#,Image,Asp.net Core,Aws Lambda,Imagesharp,我无法使用c#中的SixLabors.ImageSharp版本-1.0.0-Beta007保存jpg图像,它抛出错误。 除了GIF、PNG、JPEG、BMP格式的图像之外,还有什么解决方案可以解决这个问题 引发异常: 无法加载图像。可用解码器: GIF:GIF解码器 PNG:PngDecoder JPEG:JPEG解码器 BMP:BmpDecoder 代码: public string ResizeImage(byte[] imageBytes, int height, int wi
- GIF:GIF解码器
- PNG:PngDecoder
- JPEG:JPEG解码器
- BMP:BmpDecoder
public string ResizeImage(byte[] imageBytes, int height, int width)
{
byte[] image = new byte[] { };
using (MemoryStream inStream = new MemoryStream(imageBytes))
{
using (MemoryStream outStream = new MemoryStream())
{
using (Image imageSharp = Image.Load(inStream))
{
imageSharp.Mutate(x => x.Resize(width, height));
imageSharp.SaveAsJpeg(outStream);
imageSharp.Dispose();
}
image = outStream.ToArray();
outStream.Flush();
inStream.Flush();
}
}
return Convert.ToBase64String(image);
}
这是因为AWS在文件上传时做了一件奇怪的事情,您会发现字节[]实际上不是有效的图像文件(可通过保存原始字节数组进行测试) 这个来自另一个问题的答案应该可以帮助您重新配置AWS,以允许您的代码工作
确保流位置为零,或者尝试将流复制到新流,然后将位置设置为零,因为有时azure blob服务会关闭返回的流
using (MemoryStream stream = new MemoryStream())
using (var ms = new MemoryStream())
await largeBlob.DownloadToAsync(ms);
ms.Position = 0;
ms.CopyTo(stream);
stream.Position = 0;
var image = Image.Load(stream, out IImageFormat format)
我基本上是想找到问题并在C#中修复,而不是在AWS上,我们将基本url转换为base64以保留用于调整大小的内存流,图像来自feed etl。是否有用于将图像转换为任何格式的图像库。问题是AWS配置,而不是库,在C#中也没有任何东西。@James South AWS配置很好,从插件代码来看,它引发了异常。现在看到了这一点,我可以看出问题显然不在库中。您试图加载的图像格式不受支持,上面没有提到!!!为什么要使用station处理
中的imageSharp
对象?