创建缩略图并缩小图像尺寸
我有非常大的图像 (jpg),我想编写一个 csharp 程序来循环遍历文件并将每个图像的大小减小 75%。
我尝试了这个:
Image thumbNail = image.GetThumbnailImage(800, 600, null, new IntPtr());
但文件大小仍然很大。
有没有办法创建缩略图并使文件大小小得多?
I have very large images (jpg) and i want to write a csharp program to loop through the files and reduce the size of each image by 75%.
I tried this:
Image thumbNail = image.GetThumbnailImage(800, 600, null, new IntPtr());
but the file size is still very large.
Is there anyway to create thumbnails and have the filesize be much smaller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
用法:
将以10的质量压缩Test.jpg并保存为Test2.jpg。
编辑:作为扩展方法可能会更好:
用法:
Usage:
That will compress Test.jpg with a quality of 10 and save it as Test2.jpg.
EDIT: Might be better as an extension method:
Usage:
ImageMagick 是一个命令行工具,对于图像处理来说非常强大。 在源图像的纵横比未知或不可靠的情况下,我使用它来调整大图像的大小和创建缩略图。 ImageMagick 能够将图像大小调整为特定的高度或宽度,同时保持图片的原始纵横比。 如果需要,它还可以在图像周围添加空间。 总而言之,它非常强大,并且对处理 .nets 图像 API 进行了很好的抽象。 要在 C# 中使用 imageMagick 命令行工具,我建议使用 System.Diagnostics.ProcessStartInfo 对象,如下所示:
使用scale% 参数,您可以轻松地将图像的大小减小 75%
ImageMagick is a command line tool which is hugely powerful for doing image manipulation. I've used it for resizing large images and thumbnail creation in circumstances where the aspect ratio of the source image is unknown or is unreliable. ImageMagick is able to resize images to a specific height or width while maintaining the original aspect ratio of your picture. It can also add space around an image if required. All in all very powerful and a nice abstraction from having to deal with .nets Image APIs. To use the imageMagick command line tool from within C# I recommend using the System.Diagnostics.ProcessStartInfo object like so:
Using the scale% paramater you can easily reduce the size of your image by 75%
压缩你的图像。 对于缩略图,JPEG 就足够了,因为您不追求质量。
Compress your image. For thumbnails, JPEG is sufficient, as you're not looking for quality.
来自
GetThumbnailImage
的文档:我建议您使用较小的宽度和高度值。 尝试:
参见示例代码。
另请阅读文档:
我想您可能想看看缩放 API。
From
GetThumbnailImage
's documentation:I'd suggest you use smaller width and height values. Try:
See sample code.
Also read the documentation:
I think you may want to take a look at the scaling API.
这个方法对我很有帮助。 低图像尺寸,保持纵横比
这些都是需要的
This method helped me very well. Low image size, maintains aspect ratio
These are needed