Пример #1
0
        void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string gifPath = openFileDialog1.FileName;

            sw.Reset();
            sw.Start();
            switch (e.Argument.ToString())
            {
            case "Monochrome":
            {
                GifHelper.Monochrome(pictureBox1.ImageLocation, outGifPath);
                break;
            }

            case "RotateLeft":
            {
                GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.Rotate90FlipXY, outGifPath);
                break;
            }

            case "RotateRight":
            {
                GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.Rotate270FlipXY, outGifPath);
                break;
            }

            case "FlipH":
            {
                GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.RotateNoneFlipX, outGifPath);
                break;
            }

            case "FlipV":
            {
                GifHelper.Rotate(pictureBox1.ImageLocation, RotateFlipType.RotateNoneFlipY, outGifPath);
                break;
            }

            case "Thum50%":
            {
                GifHelper.GetThumbnail(pictureBox1.ImageLocation, 0.5, outGifPath);
                break;
            }

            case "Thum30%":
            {
                GifHelper.GetThumbnail(pictureBox1.ImageLocation, 0.3, outGifPath);
                break;
            }

            case "Thum120%":
            {
                GifHelper.GetThumbnail(pictureBox1.ImageLocation, 1.2, outGifPath);
                break;
            }

            case "Thum150%":
            {
                GifHelper.GetThumbnail(pictureBox1.ImageLocation, 1.5, outGifPath);
                break;
            }

            case "WaterMark":
            {
                GifHelper.WaterMark(pictureBox1.ImageLocation, SizeMode.Large, wmText.Text, wmText.ForceColor, wmText.Font, StartX, StartY, outGifPath);
                break;
            }

            case "WaterMarkWithImage":
            {
                GifHelper.WaterMark(pictureBox1.ImageLocation, waterImg, StartX, StartY, outGifPath);
                break;
            }

            case "Corp":
            {
                GifHelper.Crop(pictureBox1.ImageLocation, new Rectangle((int)StartX, (int)StartY, (int)(EndX - StartX), (int)(EndY - StartY)), outGifPath);
                break;
            }

            case "Merge":
            {
                GifHelper.Merge(mf.SourceFiles, outGifPath);
                openFileDialog1.FileName = outGifPath;
                break;
            }

            case "Merge1":
            {
                GifHelper.Merge(mf.SourceFiles, outGifPath, 50, true);
                openFileDialog1.FileName = outGifPath;
                break;
            }
            }
            sw.Stop();
        }
Пример #2
0
 public static string[] SaveImageAs(this HttpPostedFile postedFile, CreateFolderMode mode, WaterMarkInfo waterMarkInfo, params ThumbnailInfo[] thumbnailInfoArray)
 {
     string[] vrtualFilePaths = new string[1 + thumbnailInfoArray.Length];
     byte[]   buffer          = new byte[postedFile.ContentLength];
     postedFile.InputStream.Read(buffer, 0, buffer.Length);
     if (FileValidator.ValidateImage(buffer))
     {
         HttpContext context = HttpContext.Current;
         string      vitualFilePath, physicalFilePath;
         Image       image = Image.FromStream(new MemoryStream(buffer));
         if (image.RawFormat.Guid == ImageFormat.Gif.Guid)
         {
             vitualFilePath   = GetFilePath(postedFile, ref mode, waterMarkInfo.SavePath);
             physicalFilePath = context.Server.MapPath(vitualFilePath);
             image.Save(physicalFilePath);
             if (waterMarkInfo.Mode != WaterMarkInfo.ExecuteMode.Skip)
             {
                 if (waterMarkInfo.Mode == WaterMarkInfo.ExecuteMode.Image)
                 {
                     using (Bitmap waterImg = waterMarkInfo.GetImage())
                     {
                         float x = image.Width - waterImg.Width - 24F, y = image.Height - waterImg.Height - 24F;
                         GifHelper.WaterMark(physicalFilePath, waterImg, x, y, physicalFilePath);
                     }
                 }
                 else
                 {
                     float x = image.Width - waterMarkInfo.TextSize - 24F, y = image.Height - waterMarkInfo.TextSize - 24F;
                     GifHelper.SmartWaterMark(physicalFilePath, waterMarkInfo.Text, ColorTranslator.FromHtml(waterMarkInfo.TextColor), new Font("宋体", waterMarkInfo.TextSize), x, y, physicalFilePath);
                 }
                 vrtualFilePaths[0] = vitualFilePath;
             }
             string srcPhysicalFilePath = physicalFilePath;
             for (int i = 0; i < thumbnailInfoArray.Length;)
             {
                 ThumbnailInfo thumbnailInfo = thumbnailInfoArray[i];
                 vitualFilePath   = GetFilePath(postedFile, ref mode, thumbnailInfo.SavePath);
                 physicalFilePath = context.Server.MapPath(vitualFilePath);
                 SizeF size = GDIHelper.GetProportionSize(new SizeF(thumbnailInfo.Width, thumbnailInfo.Height), image.Size);
                 GifHelper.GetThumbnail(srcPhysicalFilePath, (double)size.Width / (double)image.Width, physicalFilePath);
                 vrtualFilePaths[++i] = vitualFilePath;
             }
         }
         else
         {
             if (waterMarkInfo.Mode != WaterMarkInfo.ExecuteMode.Skip)
             {
                 vitualFilePath   = GetFilePath(postedFile, ref mode, waterMarkInfo.SavePath);
                 physicalFilePath = context.Server.MapPath(vitualFilePath);
                 if (waterMarkInfo.Mode == WaterMarkInfo.ExecuteMode.Image)
                 {
                     using (Bitmap waterImg = waterMarkInfo.GetImage())
                     {
                         GDIHelper.MakeWaterMark(image, waterImg, ContentAlignment.BottomRight, 24);
                     }
                 }
                 else
                 {
                     GDIHelper.MakeWaterMark(image, waterMarkInfo.Text, new Font("宋体", waterMarkInfo.TextSize), ColorTranslator.FromHtml(waterMarkInfo.TextColor), ContentAlignment.BottomRight, 24);
                 }
                 image.Save(physicalFilePath);
                 vrtualFilePaths[0] = vitualFilePath;
             }
             for (int i = 0; i < thumbnailInfoArray.Length;)
             {
                 ThumbnailInfo thumbnailInfo = thumbnailInfoArray[i];
                 vitualFilePath   = GetFilePath(postedFile, ref mode, thumbnailInfo.SavePath);
                 physicalFilePath = context.Server.MapPath(vitualFilePath);
                 Bitmap thumbnailImg = GDIHelper.GetThumbnailImage(image, new SizeF(thumbnailInfo.Width, thumbnailInfo.Height), thumbnailInfo.Mode);
                 thumbnailImg.Save(physicalFilePath);
                 vrtualFilePaths[++i] = vitualFilePath;
             }
         }
         image.Dispose();
     }
     return(vrtualFilePaths);
 }