コード例 #1
0
        public static bool SaveProductMultiImage(int ProductID, string CategoryPath, HttpPostedFile OriginalFile, out string[] FileNames)
        {
            string FileSuffix = Path.GetExtension(OriginalFile.FileName).Substring(1);
            bool ProcessResult = false;
            FileNames = GetMultiImageName(ProductID, CategoryPath, FileSuffix);

            if (config.AllowedFormat.ToLower().Contains(FileSuffix.ToLower()) && config.MaxSize * 1024 >= OriginalFile.ContentLength)
            {
                ImageHelper ih = new ImageHelper();

                ih.LoadImage(OriginalFile.InputStream);

                for (int i = 2; i >= 0; i--)
                {
                    if (config.ImageTypes[i].Width > 0 && config.ImageTypes[i].Height > 0)
                    {
                        ih.ScaleImageByFixSize(config.ImageTypes[i].Width, config.ImageTypes[i].Height, true);
                    }
                    FileInfo tempFile = new FileInfo(config.PathRoot + FileNames[i].Replace("/", "\\"));
                    if (!tempFile.Directory.Exists) tempFile.Directory.Create();

                    ih.SaveImage(tempFile.FullName);
                }

                ih.Dispose();

                ProcessResult = true;
            }

            return ProcessResult;
        }
コード例 #2
0
        public static bool SaveProductMainImage(int ProductID, HttpPostedFile OriginalFile, out string[] FileNames)
        {
            string FileSuffix = Path.GetExtension(OriginalFile.FileName).Substring(1);
            bool ProcessResult = false;
            FileNames = GetMainImageName(ProductID, FileSuffix);
            if (!Directory.Exists(config.PathRoot)) Directory.CreateDirectory(config.PathRoot);

            if (config.AllowedFormat.ToLower().Contains(FileSuffix.ToLower()) && config.MaxSize * 1024 >= OriginalFile.ContentLength)
            {
                ImageHelper ih = new ImageHelper();

                ih.LoadImage(OriginalFile.InputStream);

                for (int i = 2; i >= 0; i--)
                {
                    if (config.ImageSets[i].Width > 0 && config.ImageSets[i].Height > 0)
                    {
                        ih.ScaleImageByFixSize(config.ImageSets[i].Width, config.ImageSets[i].Height, true);
                    }
                    ih.SaveImage(config.PathRoot + FileNames[i]);
                }

                ih.Dispose();
                //foreach (string FileName in FileNames)
                //{
                //    //缩小图片为设置尺寸注意图片尺寸与名称对应
                //    OriginalFile.SaveAs(config.PathRoot + FileName);
                //}

                ProcessResult = true;
            }

            return ProcessResult;
        }