如何检查图像的尺寸,以便按比例缩小图像以避免失真?
当人们写文章时,他们会提交一张照片来说明事件。但是,展示的空间并不宽阔。因此,我想减少它们的宽度和/或高度,同时保持其原始比例。否则,图像会失真。
假设最大宽度为 300px。任何比这更宽的宽度都会减少到 300 像素。但是,我希望高度减少到相同的比例。例如:600 x 800 将变为 300px x 400px。因此,我需要能够检查尺寸,
如何检查这些尺寸? 我什么时候检查它们? (i) 上传后,(ii) 从数据库检索时?...
感谢您的帮助
When people write an article, they submit a photo to illustrate the event. But, the space to display is not wide. So, I'd like to reduce they width and/or height while keeping their original proportion. Otherwise, the image gets distorted.
Let's say the max width is 300px. Anyting wider than that would see its width reduced to 300px. However, I'd like the Height to be reduced to the same proportion. For instance: 600 x 800 will become 300px x 400px. So, I need to be able to check the dimensions
How do I check those dimensions?
When do I check them? (i) after uploading, (ii) while retreiving from the database?...
Thanks for helping
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您在上传后检查图像并将两个版本保存到数据库中 - 原始版本和调整大小的版本。您应该将调整大小的版本与文章一起提供。这样您只需调整图像大小一次。
有关代码示例,请查看此处:
C#:在保持宽高比和最大高度的同时调整图像大小
I would suggest you check the image after upload and save two versions to the database - the original and the resized version. You should serve the resized versions with the article. That way you resize the image only once.
For code example take a look here:
C#: Resize An Image While Maintaining Aspect Ratio and Maximum Height