コード例 #1
0
 public PictureWaterMark(System.Drawing.Image sourceImg, System.Drawing.Image waterImg, float tranparence, MarkLocation markLocation, CompressSize compressSize)
 {
     this._sourceImage  = sourceImg;
     this._markType     = MarkType.Image;
     this._waterImage   = waterImg;
     this._transparence = tranparence;
     this._markLocation = markLocation;
     if (compressSize != CompressSize.None)
     {
         this._compressSize = compressSize;
     }
 }
コード例 #2
0
 public PictureWaterMark(System.Drawing.Image sourceImg, string text, System.Drawing.Font textFont, System.Drawing.Color color, float tranparence, MarkLocation markLocation, CompressSize compressSize)
 {
     this._textFont     = textFont;
     this._sourceImage  = sourceImg;
     this._transparence = tranparence;
     this._markType     = MarkType.Text;
     this._text         = text;
     this._textColor    = color;
     this._markLocation = markLocation;
     if (compressSize != CompressSize.None)
     {
         this._compressSize = compressSize;
     }
 }
コード例 #3
0
 protected override void EncodeParameterCore(ref string res)
 {
     res += CompressSize.ToString() + " ";
     res += ExpandSize.ToString() + " ";
 }
コード例 #4
0
        private void GetNewSize(System.Drawing.Image sourceImg, System.Drawing.Image waterImg, CompressSize compressSize, out double width, out double height)
        {
            double num  = (double)(sourceImg.Height * sourceImg.Width);
            double num2 = DataConvert.ToDouble(waterImg.Height) / DataConvert.ToDouble(waterImg.Width);
            int    num3;

            if (compressSize <= CompressSize.Compress9)
            {
                if (compressSize == CompressSize.None)
                {
                    num3 = 1;
                    goto IL_78;
                }
                if (compressSize == CompressSize.Compress4)
                {
                    num3 = 4;
                    goto IL_78;
                }
                if (compressSize == CompressSize.Compress9)
                {
                    num3 = 9;
                    goto IL_78;
                }
            }
            else
            {
                if (compressSize == CompressSize.Compress16)
                {
                    num3 = 16;
                    goto IL_78;
                }
                if (compressSize == CompressSize.Compress25)
                {
                    num3 = 25;
                    goto IL_78;
                }
                if (compressSize == CompressSize.Compress36)
                {
                    num3 = 36;
                    goto IL_78;
                }
            }
            num3 = 1;
IL_78:
            if (compressSize != CompressSize.None)
            {
                width  = Math.Sqrt(num / (double)num3 / num2);
                height = width * num2;
            }
            else
            {
                width  = (double)waterImg.Width;
                height = (double)waterImg.Height;
            }
            if (width > (double)sourceImg.Width && height > (double)sourceImg.Height)
            {
                width  = (double)sourceImg.Width;
                height = (double)sourceImg.Height;
                return;
            }
            if (width > (double)sourceImg.Width)
            {
                width  = (double)sourceImg.Width;
                height = width * num2;
                return;
            }
            if (height > (double)sourceImg.Height)
            {
                height = (double)sourceImg.Height;
                width  = height / num2;
            }
        }
コード例 #5
0
 public System.Drawing.Image Mark(System.Drawing.Image img, MarkType markType, string text, System.Drawing.Image waterImg, int markx, int marky, bool bold, System.Drawing.Color textColor, float transparence, System.Drawing.FontFamily fontFamily, int fontSize, CompressSize compressSize)
 {
     Guid[] frameDimensionsList = img.FrameDimensionsList;
     System.Drawing.Image result;
     for (int i = 0; i < frameDimensionsList.Length; i++)
     {
         Guid guid = frameDimensionsList[i];
         System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(guid);
         if (img.GetFrameCount(dimension) > 1)
         {
             result = img;
             return(result);
         }
     }
     try
     {
         System.Drawing.Imaging.ImageCodecInfo    encoderInfo       = PictureWaterMark.GetEncoderInfo("image/jpeg");
         System.Drawing.Imaging.Encoder           quality           = System.Drawing.Imaging.Encoder.Quality;
         System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters(1);
         System.Drawing.Imaging.EncoderParameter  encoderParameter  = new System.Drawing.Imaging.EncoderParameter(quality, 100L);
         encoderParameters.Param[0] = encoderParameter;
         if (markType == MarkType.Text)
         {
             System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
             bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
             System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
             graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
             graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
             graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
             graphics.DrawImage(img, new System.Drawing.Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
             System.Drawing.Font  textFont = this.TextFont;
             System.Drawing.SizeF sizeF    = default(System.Drawing.SizeF);
             float num = this.TextFont.Size - 2f;
             if ((double)num < 0.0001)
             {
             }
             sizeF = graphics.MeasureString(this.Text, textFont);
             while ((ushort)sizeF.Width > (ushort)img.Width)
             {
                 num = this.TextFont.Size - 2f;
                 if ((double)num < 0.0001)
                 {
                     break;
                 }
                 this.TextFont = new System.Drawing.Font(this.TextFont.FontFamily, num, this.TextFont.Style);
                 sizeF         = graphics.MeasureString(this.Text, this.TextFont);
                 if ((ushort)sizeF.Width < (ushort)this.SourceImage.Width)
                 {
                     break;
                 }
             }
             int alpha = Convert.ToInt32(255f * transparence);
             System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(alpha, textColor));
             graphics.DrawString(text, textFont, brush, (float)markx, (float)marky);
             graphics.Dispose();
             img = this.ConvertBmpToNewImg(bitmap, encoderInfo, encoderParameters);
             bitmap.Dispose();
             result = img;
         }
         else
         {
             if (markType == MarkType.Image)
             {
                 float[][] array     = new float[5][];
                 float[][] arg_236_0 = array;
                 int       arg_236_1 = 0;
                 float[]   array2    = new float[5];
                 array2[0]            = 1f;
                 arg_236_0[arg_236_1] = array2;
                 float[][] arg_24D_0 = array;
                 int       arg_24D_1 = 1;
                 float[]   array3    = new float[5];
                 array3[1]            = 1f;
                 arg_24D_0[arg_24D_1] = array3;
                 float[][] arg_264_0 = array;
                 int       arg_264_1 = 2;
                 float[]   array4    = new float[5];
                 array4[2]            = 1f;
                 arg_264_0[arg_264_1] = array4;
                 float[][] arg_278_0 = array;
                 int       arg_278_1 = 3;
                 float[]   array5    = new float[5];
                 array5[3]            = transparence;
                 arg_278_0[arg_278_1] = array5;
                 array[4]             = new float[]
                 {
                     0f,
                     0f,
                     0f,
                     0f,
                     1f
                 };
                 float[][] newColorMatrix = array;
                 System.Drawing.Imaging.ColorMatrix     newColorMatrix2 = new System.Drawing.Imaging.ColorMatrix(newColorMatrix);
                 System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
                 imageAttributes.SetColorMatrix(newColorMatrix2, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default);
                 System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                 bitmap2.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                 System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap2);
                 graphics2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                 graphics2.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                 graphics2.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                 graphics2.DrawImage(img, new System.Drawing.Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
                 if (waterImg.Width > img.Width || waterImg.Height > img.Height)
                 {
                     System.Drawing.Image.GetThumbnailImageAbort callback = null;
                     System.Drawing.Image image = null;
                     if (this.CompressSize == CompressSize.None)
                     {
                         image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width, this.SourceImage.Height, callback, new IntPtr(0));
                     }
                     else
                     {
                         if (this.CompressSize == CompressSize.Compress4)
                         {
                             image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 2, this.SourceImage.Height / 2, callback, new IntPtr(0));
                         }
                         else
                         {
                             if (this.CompressSize == CompressSize.Compress9)
                             {
                                 image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 3, this.SourceImage.Height / 3, callback, new IntPtr(0));
                             }
                             else
                             {
                                 if (this.CompressSize == CompressSize.Compress16)
                                 {
                                     image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 4, this.SourceImage.Height / 4, callback, new IntPtr(0));
                                 }
                             }
                         }
                     }
                     if (this.CompressSize == CompressSize.Compress25)
                     {
                         image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 5, this.SourceImage.Height / 5, callback, new IntPtr(0));
                     }
                     if (this.CompressSize == CompressSize.Compress36)
                     {
                         image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 6, this.SourceImage.Height / 6, callback, new IntPtr(0));
                     }
                     graphics2.DrawImage(image, new System.Drawing.Rectangle(markx, marky, image.Width, image.Height), 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
                     image.Dispose();
                     graphics2.Dispose();
                     img = this.ConvertBmpToNewImg(bitmap2, encoderInfo, encoderParameters);
                     bitmap2.Dispose();
                     result = img;
                 }
                 else
                 {
                     graphics2.DrawImage(waterImg, new System.Drawing.Rectangle(markx, marky, waterImg.Width, waterImg.Height), 0, 0, waterImg.Width, waterImg.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
                     graphics2.Dispose();
                     img = this.ConvertBmpToNewImg(bitmap2, encoderInfo, encoderParameters);
                     bitmap2.Dispose();
                     result = img;
                 }
             }
             else
             {
                 result = img;
             }
         }
     }
     catch
     {
         result = img;
     }
     return(result);
 }