Пример #1
0
        /// <summary>
        /// 上传指定的文件,并返回是否上传成功!
        /// </summary>
        /// <param name="PostFile">文件对象</param>
        /// <param name="FileName">文件名称,如果不设置则自动分配一个</param>
        /// <param name="width">上传图片的宽度限制</param>
        /// <param name="height">上传图片的高度限制,当为-1时则自动计算高</param>
        /// <param name="min">缩略图对象,如果不须要请设置为null;</param>
        public bool UpImage(HttpPostedFile PostFile, string FileName, int width, int height, UpFilesMin min)
        {
            if (!UpFile(PostFile, FileName))
            {
                return(false);
            }

            //string tmpDir, tmpFile, tmp;
            //tmpFile = Path.GetFileNameWithoutExtension(tmpName);
            string tmpDir, tmp;

            tmpDir = Path.GetDirectoryName(tmpName);
            ImageFormat imgformat;

            Image img = null;

            try
            {
                //当不为jpg时将图片转换为jpg
                if (IsToJpeg && !tmpName.ToLower().EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))
                {
                    tmpName     = DisposeImage.ConvertFormat(tmpName, ImageFormat.Jpeg);
                    this.Result = Path.GetFileName(tmpName);
                }
                else if (IsToGif && !tmpName.ToLower().EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
                {
                    tmpName     = DisposeImage.ConvertFormat(tmpName, ImageFormat.Gif);
                    this.Result = Path.GetFileName(tmpName);
                }


                //大图宽高限制
                if (width > 0)
                {
                    new DisposeImage(tmpName).CompressImage(width, height);
                }
                //缩略图
                if (min != null)
                {
                    if (string.IsNullOrEmpty(min.MinPath))
                    {
                        min.MinPath = tmpDir += "\\Min";
                    }
                    if (!Directory.Exists(min.MinPath))
                    {
                        Directory.CreateDirectory(min.MinPath);
                        //this.Result = string.Format("缩略图目录{0}不存在!", min.MinPath);
                        //return false;
                    }

                    img       = Image.FromFile(tmpName);//打开现在文件
                    imgformat = img.RawFormat;
                    Image imgB = img.GetThumbnailImage(min.Width, min.Height, null, IntPtr.Zero);
                    if (string.IsNullOrEmpty(min.FileName))
                    {
                        tmp = string.Format("{0}\\{1}", min.MinPath, Path.GetFileName(tmpName));
                    }
                    else
                    {
                        tmp = string.Format("{0}\\{1}", min.MinPath, min.FileName + Path.GetExtension(tmpName));
                    }
                    img.Dispose();
                    imgB.Save(tmp, imgformat);
                    imgB.Dispose();
                    if (MinImgMark != null) //水印
                    {
                        if (MinImgMark.Create(tmp))
                        {
                            throw new AooshiException(" Create Mark Error : " + MinImgMark.ErrorMessage);
                        }
                    }
                }

                //水印
                if (ImgMark != null)
                {
                    //ImgMark.FileNamePath = tmpName;
                    //if (!ImgMark.Create()) throw new Exception(ImgMark.ErrorMessage);

                    if (ImgMark.Create(tmpName))
                    {
                        throw new AooshiException(" Create Mark Error : " + ImgMark.ErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                this.Result = ex.Message;
                return(false);
            }
            finally
            {
                if (img != null)
                {
                    img.Dispose();
                }
            }

            return(true);
        }
Пример #2
0
 /// <summary>
 /// 上传指定的文件,并返回是否上传成功!
 /// </summary>
 /// <param name="PostFile">文件对象</param>
 /// <param name="min">缩略图路径,如果不设置则自动在原路径上再进入Min目录层</param>
 public bool UpImage(HttpPostedFile PostFile, UpFilesMin min)
 {
     return(UpImage(PostFile, null, -1, -1, min));
 }
Пример #3
0
 /// <summary>
 /// 上传指定的文件,并返回是否上传成功!
 /// </summary>
 /// <param name="PostFile">文件对象</param>
 /// <param name="FileName">文件名称,如果不设置则自动分配一个</param>
 /// <param name="min">缩略图路径,如果不设置则自动在原路径上再进入Min目录层</param>
 public bool UpImage(HttpPostedFile PostFile, string FileName, UpFilesMin min)
 {
     return(UpImage(PostFile, FileName, -1, -1, min));
 }
Пример #4
0
 /// <summary>
 /// 上传指定的文件,并返回是否上传成功!
 /// </summary>
 /// <param name="PostFile">文件对象</param>
 /// <param name="width">图的宽度限制</param>
 /// <param name="height">图的高度限制,当为-1时则自动计算高</param>
 /// <param name="min">缩略图路径,如果不设置则自动在原路径上再进入Min目录层</param>
 public bool UpImage(HttpPostedFile PostFile, int width, int height, UpFilesMin min)
 {
     return(UpImage(PostFile, null, width, height, min));
 }