[英]unable to process .jpg images using SixLabors.ImageSharp in c# - Version 1.0.0-beta0007
I am unable to save the jpg image using SixLabors.ImageSharp version - 1.0.0-beta0007 in c#, It throws error.我无法在 C# 中使用 SixLabors.ImageSharp 版本 - 1.0.0-beta0007 保存 jpg 图像,它会抛出错误。 Is there any solution to fix the issue beside GIF,PNG,JPEG,BMP format images.
除了 GIF、PNG、JPEG、BMP 格式图像之外,是否有任何解决方案可以解决此问题。
Throws Exception:抛出异常:
Image cannot be loaded.无法加载图像。 Available decoders:
可用解码器:
Code:代码:
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);
}
Make sure the stream position is zero or try to copy the stream to new stream then set the position to zero because sometimes azure blob service close the returned stream确保流位置为零或尝试将流复制到新流然后将位置设置为零,因为有时 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)
This will be because of a strange thing the AWS does with file uploads you will find the byte[] isn't actually a valid image file (testable by saving the raw byte array out).这是因为 AWS 对文件上传做了一件奇怪的事情,你会发现 byte[] 实际上不是一个有效的图像文件(可以通过保存原始字节数组进行测试)。
This answer from another question should help you reconfigure AWS to allow your code to work.这个来自另一个问题的答案应该可以帮助您重新配置 AWS 以允许您的代码工作。
https://stackoverflow.com/a/56695747/234855 https://stackoverflow.com/a/56695747/234855
I also came across this issue.我也遇到了这个问题。 The code is shown below.
代码如下所示。
byte[] pixelData = new byte[16] { 0, 0 ,0,0,
1,1,1,1,
2,2,2,2,
3,3,3,3};
Image image = Image.Load(pixelData);
image.SaveAsBmp("pixelData.bmp");
I don't know how to solve it,either我也不知道怎么解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.