本文介绍了图像大小在C#中压缩为50 kb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想压缩图像尺寸

这里是我的代码欢迎任何建议



我尝试过:



  string  CustomerID =  ; 
if (会话[ RoleID]!= null
{
CustomerID = Request.Form [ CustomerID];

// string CustomerID = Request.Form [Customer.CustomerID];
if (CustomerID!= null
{
if (Request.Files.Count > 0
{
var file = Request.Files [ 0 ];
if (file!= null && file.ContentLength > 0
{
// var fileName = Path.GetFileName(file.FileName);
var fileExtension = Path.GetExtension(file.FileName);
var allowedExtensions = new [] { 。bmp 。png 。jpg jpeg 。gif};
if (allowedExtensions.Contains(fileExtension))
{
// 删除文件
var pathD = Server.MapPath( 〜/ Avatar / 1);
var images = Directory.GetFiles(pathD,CustomerID + *。);
for int i = 0 ; i < images.Length; i ++)
System.IO.File.Delete(Server.MapPath(( 〜/ Avatar / 1 /)+ Path.GetFileName(images [i])));

// 上传文件
var fileName = CustomerID + fileExtension;
var path = Path.Combine(Server.MapPath( 〜/ Avatar / 1 /),fileName);
file.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
file.SaveAs(path);

// 会话[头像] = fileName;
}
解决方案



i want to compress the image size
here is my code any suggetion is welcome

What I have tried:

string CustomerID = "";
           if (Session["RoleID"] != null)
           {
                   CustomerID = Request.Form["CustomerID"];

               //string CustomerID = Request.Form["Customer.CustomerID"];
               if (CustomerID != null)
               {
                   if (Request.Files.Count > 0)
                   {
                       var file = Request.Files[0];
                       if (file != null && file.ContentLength > 0)
                       {
                           //var fileName = Path.GetFileName(file.FileName);                       
                           var fileExtension = Path.GetExtension(file.FileName);
                           var allowedExtensions = new[] { ".bmp", ".png", ".jpg", "jpeg", ".gif" };
                           if (allowedExtensions.Contains(fileExtension))
                           {
                               //Delete files
                               var pathD = Server.MapPath("~/Avatar/1");
                               var images = Directory.GetFiles(pathD, CustomerID + ".*");
                               for (int i = 0; i < images.Length; i++)
                                   System.IO.File.Delete(Server.MapPath(("~/Avatar/1/") + Path.GetFileName(images[i])));

                               //Up files
                               var fileName = CustomerID + fileExtension;
                               var path = Path.Combine(Server.MapPath("~/Avatar/1/"), fileName);
                               file.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                               file.SaveAs(path);

                               //Session["Avatar"] = fileName;
                           }
解决方案




这篇关于图像大小在C#中压缩为50 kb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:09