Пример #1
0
 private string DetectInvisibleWatermark() //Extract invisible watermark
 {
     water = new Watermark(_boxSize, _errorCorrection, _opacity, _s1, _s2);
     using (CStreamReader reader = InputPicture.CreateReader())
     {
         using (Bitmap bitmap = new Bitmap(reader))
         {
             if (_stopped)
             {
                 return("");
             }
             return(water.extractText(bitmap));
         }
     }
 }
Пример #2
0
 private void CreateInvisibleWatermark() //Embed invisible Watermark
 {
     water = new Watermark(_boxSize, _errorCorrection, _opacity, _s1, _s2);
     using (CStreamReader reader = InputPicture.CreateReader())
     {
         using (Bitmap bitmap = new Bitmap(reader))
         {
             if (_stopped)
             {
                 return;
             }
             water.embed(bitmap, Watermark);
             CreateOutputStream(bitmap);
         }
     }
 }
Пример #3
0
        private void WmVisibleText() //Embed visible text
        {
            using (CStreamReader reader = InputPicture.CreateReader())
            {
                using (Bitmap bitmap = new Bitmap(reader))
                {
                    Bitmap image  = PaletteToRGB(bitmap);
                    Image  photo  = image;
                    int    width  = photo.Width;
                    int    height = photo.Height;

                    Bitmap bitmapmPhoto = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                    bitmapmPhoto.SetResolution(72, 72);
                    Graphics graphicPhoto = Graphics.FromImage(bitmapmPhoto);

                    graphicPhoto.SmoothingMode = SmoothingMode.AntiAlias;
                    graphicPhoto.DrawImage(photo, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
                    Font  font = null;
                    SizeF size = new SizeF();

                    for (int i = _textSize; i > 3; i--) //Test which is the largest possible fontsize to be used
                    {
                        if (_stopped)
                        {
                            return;
                        }
                        font = new Font(_font, i, FontStyle.Bold);
                        size = graphicPhoto.MeasureString(Watermark, font);
                        if ((ushort)size.Width < (ushort)width) //Text fits into image
                        {
                            break;
                        }
                    }

                    int yPixlesFromBottom = 0;
                    switch (_location)
                    {
                    case (int)Location.Bottom:
                        yPixlesFromBottom = (int)(height * .05);
                        break;

                    case (int)Location.Top:
                        yPixlesFromBottom = (int)(height * .95);
                        break;

                    case (int)Location.Other:
                        yPixlesFromBottom = (int)(height * _locationPercentage);
                        break;
                    }
                    float        yPosFromBottom = ((height - yPixlesFromBottom) - (size.Height / 2));
                    float        xCenterOfImg   = ((float)width / 2f);
                    StringFormat strFormat      = new StringFormat();
                    strFormat.Alignment = StringAlignment.Center;
                    SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
                    graphicPhoto.DrawString(Watermark, font, semiTransBrush2, new PointF(xCenterOfImg + 1, yPosFromBottom + 1), strFormat);
                    SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
                    graphicPhoto.DrawString(Watermark, font, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom), strFormat);

                    CreateOutputStream(bitmapmPhoto);
                }
            }
        }