Ejemplo n.º 1
0
        public Bitmap insertImageWaterMark(clsImageItem item, clsImageWaterMark WM)
        {
            Point WMPosition;
            Point SrcPosition = new Point();
            WMPosition = CalculateWMPosition(WM.Layout, WM.ImgWaterMark.Size, WM.OffSet, item.Image.Size);

            Bitmap img = new Bitmap(item.Image);
            Graphics grPhoto = Graphics.FromImage(img);

            if (WM.Layout == WaterMarkLayout.Fill)
            {
                SrcPosition.X = Math.Abs(WMPosition.X);
                SrcPosition.Y = Math.Abs(WMPosition.Y);
                WMPosition = new Point();
            }

            grPhoto.DrawImage(
                WM.ImgWaterMark,
                new Rectangle(WMPosition.X, WMPosition.Y, img.Width, img.Height),
                SrcPosition.X,
                SrcPosition.Y,
                img.Width,
                img.Height,
                GraphicsUnit.Pixel
            );

            return img;
        }
Ejemplo n.º 2
0
 public Bitmap CreateAndInsertWaterMark(clsImageItem item, clsWaterMark WM)
 {
     ///
     /// THIS IS WRONG, Should be in an IF because of textWaterMark
     ///
     CreateWMImagePiece(item, (clsImageWaterMark)WM);
     return insertImageWaterMark(item, (clsImageWaterMark)WM);
 }
Ejemplo n.º 3
0
 public Bitmap insertWaterMark(clsImageItem item, int WMIndex)
 {
     ///THIS IS WRONG, Should be in an IF because of textWaterMark
     return insertImageWaterMark(item, (clsImageWaterMark)item.WaterMarks[WMIndex]);
 }
Ejemplo n.º 4
0
 public Bitmap insertWaterMark(clsImageItem item)
 {
     ///THIS IS WRONG, Should be in a LOOP
     return insertImageWaterMark(item, (clsImageWaterMark)item.WaterMarks[0]);
 }
Ejemplo n.º 5
0
 public void CreateWaterMark(clsImageItem item)
 {
     CreateWMImagePiece(item, (clsImageWaterMark)item.WaterMarks[0]);
 }
Ejemplo n.º 6
0
 public Bitmap CreateAndInsertWaterMark(clsImageItem item)
 {
     return CreateAndInsertWaterMark(item, item.WaterMarks[0]);
 }
Ejemplo n.º 7
0
        private void CreateWMImagePiece(clsImageItem item, clsImageWaterMark WM)
        {
            Size NewWMSize = new Size();
            Point WMPosition = new Point();

            NewWMSize = CalculateWMSize(WM.Layout, WM.ImgWaterMark.Size, item.Image.Size);
            WMPosition = CalculateWMPosition(WM.Layout, NewWMSize, WM.OffSet, item.Image.Size);

            Bitmap imgPiece = new Bitmap(NewWMSize.Width, NewWMSize.Height, PixelFormat.Format24bppRgb);
            imgPiece.SetResolution(item.Image.HorizontalResolution, item.Image.VerticalResolution);
            Graphics grPiece = Graphics.FromImage(imgPiece);

            grPiece.DrawImage(
                item.Image,
                new Rectangle(0, 0, imgPiece.Width, imgPiece.Height),
                WMPosition.X,
                WMPosition.Y,
                imgPiece.Width,
                imgPiece.Height,
                GraphicsUnit.Pixel
            );

            ImageAttributes imgAttrib = new ImageAttributes();

            if (WM.HasTransparentColor)
            {
                ColorMap colorMap = new ColorMap();
                colorMap.OldColor = WM.TransparentColor;
                colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
                ColorMap[] remapTable = { colorMap };
                imgAttrib.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
            }

            float[][] colorMatrixElements = {
                new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                new float[] {0.0f,  0.0f,  0.0f,  (float)(1.0 - WM.Transparency / 100.0), 0.0f},
                new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
            };
            ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);

            imgAttrib.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            if (WM.Layout == WaterMarkLayout.Repeat)
            {
                DrawWaterMarkRepetition(ref WM, NewWMSize, imgAttrib);
            }

            grPiece.DrawImage(
                WM.ImgWaterMark,
                new Rectangle(0, 0, NewWMSize.Width, NewWMSize.Height),
                0,
                0,
                WM.Width,
                WM.Height,
                GraphicsUnit.Pixel,
                imgAttrib
            );

            grPiece.Dispose();

            WM.ImgWaterMark = imgPiece;
        }
Ejemplo n.º 8
0
 private void CreateWMImagePiece(clsImageItem item, int WMIndex)
 {
     CreateWMImagePiece(item, (clsImageWaterMark)item.WaterMarks[WMIndex]);
 }