如何将照片从mb压缩到kb [英] How to compress a photo from mb to kb

查看:543
本文介绍了如何将照片从mb压缩到kb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照以下链接,您可以在其中找到以下代码。



使用C#动态调整图像大小 [ ^ ]

{

Bitmap imgIn = new Bitmap(path); ---- ----------->这是通过参数无效的错误。



double y = imgIn.Height;

double x = imgIn.Width;



double factor = 1;

if(width> 0)

{





TIA



我尝试了什么:



i试图压缩照片



例如:一张上传前有1MB的照片然后必须压缩成KB

follow the below link and you can find the below code in that.

Resizing image dynamically using C#[^]
{
Bitmap imgIn = new Bitmap(path);--------------->It is throughing an error like parameter is not valid.

double y = imgIn.Height;
double x = imgIn.Width;

double factor = 1;
if (width > 0)
{


TIA

What I have tried:

i have tryed to compress the photo

for example: one photo having 1MB before uploading then it have to be compress into KB

推荐答案

这不是一篇非常好的文章或技术IMO。您需要确保path是服务器文件系统上文件的物理位置。如果您查看文章的底部,则会介绍如何使用该链接。由于我们不知道您是如何调用代码的,我们无法确切地说出问题所在,但正如我所说的路径需要引用服务器文件系统上的图像。
That's not a very good article or technique IMO. You need to ensure the "path" is the physical location of the file on the server's file system. If you look at the bottom of the article there is a description of how to use the link. As we don't know how you are calling your code we can't really say what the problem is, but as I said "path" needs to refer to an image on the server's file system.


Quote:

如何将照片从mb压缩到kb

How to compress a photo from mb to kb



简答:你不能。压缩不是无限的。



唯一可行的方法是制作缩略图(小图片)

你需要通过减少缩小图片尺寸像素数高度和宽度。

图像缩放 - 维基百科,免费的百科全书 [< a href =https://en.wikipedia.org/wiki/Image_scaling\"target =_ blanktitle =New Window> ^ ]


这篇关于如何将照片从mb压缩到kb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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