通过指定高度或宽度在ASP.NET C#中按比例调整图像大小 [英] Resizing image proportionally in ASP.NET C# by specifying either Height or Width

查看:355
本文介绍了通过指定高度或宽度在ASP.NET C#中按比例调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个code,让我来调整图像,但具有以下功能:

I need a code that will allow me to resize images, but with the following functionality:

1)调整后上传图片

2)按比例通过指定高度或宽度调整图像大小。

2) Resize image proportionally by specifying either height or width.

请注意:


  • 如果在ASP.NET C#来完成

例如:该功能应该得到的宽度或高度,按比例调整图片的大小为给予高度或宽度。比方说,图像为400(W)X100(H)。我想告诉函数来调整图像到一个特定的高度,让我们说80px。该函数应该按比例调整图像大小,同时设置图像高度为80px,并相应的宽度。另一种选择是TI告诉函数的宽度,比方说200像素,并且函数应该调整图片大小为200像素宽,设置相应的高度。

For example: The function should get the a width OR a height, and resize the image proportionally for the give height OR Width. Let's say that the image is 400(w)x100(h). I want to tell the function to resize the image to a specific height, let's say 80px. The function should resize the image proportionally while setting the image height to 80px and the width accordingly. Another option is ti tell the function the width, let's say 200px, and the function should resize the image to 200px width and set the height accordingly.

3)将图像保存到特定的位置(路径)。

3) save the image to a specific location (path).

4)功能可以上传图像或通过指定图像路径工作。

4) Function can work with uploaded image or by specifying an image path.

5)我希望能够选择的图像质量

5) I want to be able to choose the image quality

6)只需要这个JPEG

6) Only need this for JPEG

有人可以帮我了这一点。谢谢你。

Can somebody please help me out with this. Thanks.

推荐答案

虽然好像你应该​​能够复制和粘贴片段来做到这一点,的有一吨,你需要看出来,如果​​你建立自己的图片大小系统的陷阱。这是更好地使用经过验证,测试和支持开放源码库

Although it seems like you should be able to copy and paste a snippet to do this, there are a ton of pitfalls you need to look out for if you're building your own image resizing system. It's better to use a proven, tested, and supported open-source library.

要直接从HttpPostedFile调整到一个文件,通话

To resize to a file directly from HttpPostedFile, call

ImageBuilder.Current.Build(httpPostedFile, "img.jpg", new ResizeSettings("width=200&quality=90"));

要调整现有文件,调用

ImageBuilder.Current.Build("orig.jpg", "img.jpg", new ResizeSettings("width=200&quality=90"));

借助 ImageResizing.Net 库是免费的,MIT授权(有关许可的问题,没有后​​顾之忧)。

The ImageResizing.Net library is free, and MIT-licensed (no worries about licensing problems).

这篇关于通过指定高度或宽度在ASP.NET C#中按比例调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆