通过指定高度或宽度在 ASP.NET C# 中按比例调整图像大小
我需要一个允许我调整图像大小的代码,但具有以下功能:
1)上传时调整图像大小
2)通过指定高度或宽度按比例调整图像大小。
注意:
- 应在 ASP.NET C# 中完成,
例如:该函数应获取宽度或高度,并根据给定的高度或宽度按比例调整图像大小。假设图像的尺寸为 400(w)x100(h)。我想告诉函数将图像大小调整到特定高度,比如说 80px。该函数应按比例调整图像大小,同时将图像高度设置为 80px,宽度相应设置。另一种选择是告诉函数宽度,比如说 200px,函数应该将图像大小调整为 200px 宽度并相应地设置高度。
3)将图像保存到特定位置(路径)。
4) 函数可以使用上传的图像或指定图像路径。
5) 我希望能够选择图像质量
6) 仅需要 JPEG
有人可以帮我解决这个问题吗?谢谢。
I need a code that will allow me to resize images, but with the following functionality:
1) resize image upon upload
2) Resize image proportionally by specifying either height or width.
Note:
- Should be done in ASP.NET C#
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) save the image to a specific location (path).
4) Function can work with uploaded image or by specifying an image path.
5) I want to be able to choose the image quality
6) Only need this for JPEG
Can somebody please help me out with this. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尽管您似乎应该能够复制并粘贴代码片段来执行此操作,但有如果您正在构建自己的图像调整大小系统,则需要注意大量陷阱。最好使用经过验证、测试且受支持的开源库。
要直接从 HttpPostedFile 调整文件大小,请调用
要调整现有文件大小,请调用
ImageResizing.Net 库是免费的,并且 MIT - 已获得许可(无需担心许可问题)。
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.
To resize to a file directly from HttpPostedFile, call
To resize an existing file, call
The ImageResizing.Net library is free, and MIT-licensed (no worries about licensing problems).
最后一天,我发现了 imageresizer ,它非常棒。和良好的API。效果很好。
从 Visual studio 2010 扩展管理器下载:http://nuget.org/。
在 VS-2010 中下载 API 的简单步骤:
1)。安装扩展 http://nuget.org/。
3)。查找并安装 ImageResizing

4).然后代码:(我在这里使用裁剪。您可以使用任何)imageresizing.net 上的文档
尝试一下!它非常好用并且易于使用。谢谢。
Last day I found imageresizer and its great. and good API. Works Great.
Downloaded from Visual studio 2010 Extension Manager: http://nuget.org/.
Easy Steps to download API in VS-2010:
1). Install Extension http://nuget.org/.
3). Find and Install ImageResizing

4).Then Code: (I m using here cropping. you can use any) Documentation on imageresizing.net
Try!!! its very awsumm and easy to use. thanks.
摘自这个 Stackoverflow 答案,我想出了
:指定其 maxWidth 调整图像大小:
指定其 maxHeight 调整图像大小:
Taken from this Stackoverflow answer, I come up with:
To resize Image specifying its maxWidth:
To resize Image specifying its maxHeight:
的做法:
这就是我的项目在上传文件时单击按钮时
This is how is did in my project
On Button click while uploading file: