| | |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using System.Drawing; |
| | | using System.Drawing.Imaging; |
| | | using System.IO; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | |
| | | { |
| | | File.Delete(fileurl); //删除指定文件 |
| | | files.SaveAs(fileurl); |
| | | |
| | | |
| | | |
| | | string StrPath = "/files/"+ HBillNo+"/"+ filename; |
| | | if (File.Exists(fileurl)) |
| | | { |
| | |
| | | { |
| | | Directory.CreateDirectory(fileSavePath); //添加文件夹 |
| | | files.SaveAs(fileurl); |
| | | |
| | | |
| | | |
| | | |
| | | string StrPath = "/files/" + HBillNo + "/" + filename; |
| | | if (File.Exists(fileurl)) |
| | | { |
| | |
| | | return Result_Ob; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | { |
| | | File.Delete(fileurl); //删除指定文件 |
| | | files.SaveAs(fileurl); |
| | | |
| | | fileurl = ImgCompress(50L, fileurl, fileSavePath, files); |
| | | |
| | | string StrPath = "/files/" + HBillNo + "/" + filename; |
| | | if (File.Exists(fileurl)) |
| | | { |
| | |
| | | { |
| | | Directory.CreateDirectory(fileSavePath); //添加文件夹 |
| | | files.SaveAs(fileurl); |
| | | |
| | | fileurl = ImgCompress(50L, fileurl, fileSavePath, files); |
| | | |
| | | string StrPath = "/files/" + HBillNo + "/" + filename; |
| | | if (File.Exists(fileurl)) |
| | | { |
| | |
| | | return Result_Ob; |
| | | } |
| | | |
| | | //压缩方法 |
| | | private string ImgCompress(long level, string fileurl, string fileSavePath, HttpPostedFile files) |
| | | { |
| | | Image img = Image.FromFile(fileurl); |
| | | ImageFormat imgFormat = img.RawFormat; |
| | | EncoderParameters encoderParams = new EncoderParameters(); |
| | | encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, level); |
| | | ImageCodecInfo codecInfo = GetEncoder(imgFormat); |
| | | |
| | | var filed = files.FileName.Split('.'); |
| | | string filenames = filed[0].ToString() + "_1." + filed[1].ToString(); |
| | | fileurl = Path.Combine(fileSavePath, filenames); |
| | | |
| | | string savePath = fileurl; |
| | | |
| | | img.Save(savePath, codecInfo, encoderParams); |
| | | img.Dispose(); |
| | | return fileurl; |
| | | } |
| | | private ImageCodecInfo GetEncoder(ImageFormat format) |
| | | { |
| | | ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); |
| | | foreach (ImageCodecInfo codec in codecs) |
| | | { |
| | | if (codec.FormatID == format.Guid) |
| | | { |
| | | return codec; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 输出json结果 返回2个值 result (输出succes的值) returnval (输出str的值) |
| | | /// </summary> |