热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

我重新调整了上传的图片,但它仍然有很大的尺寸-Iresizeduploadedimagesbutitstillhavebigsize

Iusedtousethiscodetoresizetheuploadedimage,butwhenIcomparedthegeneratedimagewitho

I used to use this code to resize the uploaded image, but when I compared the generated image with other images in other websites, I found that It have large size !!

我曾经使用这段代码来调整上传的图像大小,但是当我将生成的图像与其他网站中的其他图像进行比较时,我发现它有大尺寸!!

System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath(filePath));

            int mediumWidth = 350;
            int mediumHeight = mediumWidth * img.Height / img.Width;
            System.Drawing.Bitmap bmw = new System.Drawing.Bitmap(img, mediumWidth, mediumHeight);//resize image
            bmw.Save(MapPath("~/image/thumb/") + fileName);
            bmw.Dispose();

the generated image have 200 Kb, but in other websites it have 20 kb.. Is there a problem with my code ?

生成的图像有200 Kb,但在其他网站上它有20 kb ..我的代码有问题吗?

1 个解决方案

#1


2  

You're saving it as a bitmap, which is uncompressed. Other websites are probably using jpeg encoding, which results in much smaller file sizes.

您将其保存为未压缩的位图。其他网站可能使用jpeg编码,这导致文件大小更小。

Try using the Save overload which allows specifying encoding instead:

尝试使用Save overload,它允许指定编码:

bmw.Save(MapPath("~/image/thumb/") + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

推荐阅读
author-avatar
花痴-耐你们_304
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有