Azure webjob 图像调整大小问题
Azure webjob image resize issue
我正在使用 azure web 作业来保存图像的缩略图,这是执行此操作的代码
ImageProcessor.Imaging.Formats.FormatBase f;
f = new ImageProcessor.Imaging.Formats.JpegFormat();
Size size = new Size(200, 200);
using (WebClient client = new WebClient())
{
MemoryStream stream = new MemoryStream(client.DownloadData(input));
MemoryStream stream2 = new MemoryStream();
int quality = 110;
do
{
quality = quality - 10;
using (ImageFactory factory = new ImageFactory(false))
{
factory.Load(stream)
.Format(f)
.Resize(size)
//.BackgroundColor(Color.White)
.Quality(quality)
.Save(stream2);
}
} while (stream2.Length > stream.Length || stream2.Length ==100000);
例如,当我将带有 this 图片的消息添加到队列时,
工作应该给我拇指图像 200 * 200 但在结果图像的顶部和底部有尾部黑色区域,如 this 不应该这样做
为什么要这样做???
您正在尝试使矩形适合正方形。
来自http://imageprocessor.org/imageprocessor/imagefactory/resize/:
Resize
Resizes the current image to the given dimensions. If EXIF metadata is to be preserved the information contained within will also be updated to match.
public ImageFactory Resize(Size size)
Parameters
size:
The System.Drawing.Size
containing the width and height to set the image to.
Passing a 0 for either dimension will omit that dimension.
所以,传入0
作为高度以保持纵横比,
Size size = new Size(200, 0);
或使用其他调整大小模式之一:Crop/Min/Max/Stretch
我正在使用 azure web 作业来保存图像的缩略图,这是执行此操作的代码
ImageProcessor.Imaging.Formats.FormatBase f;
f = new ImageProcessor.Imaging.Formats.JpegFormat();
Size size = new Size(200, 200);
using (WebClient client = new WebClient())
{
MemoryStream stream = new MemoryStream(client.DownloadData(input));
MemoryStream stream2 = new MemoryStream();
int quality = 110;
do
{
quality = quality - 10;
using (ImageFactory factory = new ImageFactory(false))
{
factory.Load(stream)
.Format(f)
.Resize(size)
//.BackgroundColor(Color.White)
.Quality(quality)
.Save(stream2);
}
} while (stream2.Length > stream.Length || stream2.Length ==100000);
例如,当我将带有 this 图片的消息添加到队列时, 工作应该给我拇指图像 200 * 200 但在结果图像的顶部和底部有尾部黑色区域,如 this 不应该这样做 为什么要这样做???
您正在尝试使矩形适合正方形。
来自http://imageprocessor.org/imageprocessor/imagefactory/resize/:
Resize
Resizes the current image to the given dimensions. If EXIF metadata is to be preserved the information contained within will also be updated to match.
public ImageFactory Resize(Size size)
Parameters
size:
The
System.Drawing.Size
containing the width and height to set the image to.
Passing a 0 for either dimension will omit that dimension.
所以,传入0
作为高度以保持纵横比,
Size size = new Size(200, 0);
或使用其他调整大小模式之一:Crop/Min/Max/Stretch