Beispiel #1
0
 private void btnRemoveImageWaterMark_Click(object sender, EventArgs e)
 {
     imgWM = null;
     pbWatermark.Image = null;
     EnableDisableButtons(false);
     SelectImageFromGrid();
 }
        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;
        }
        /// <summary>
        /// WaterMark the list of images with a specific ImageWaterMark
        /// </summary>
        public void ImageWaterMark(clsImageWaterMark WaterMark)
        {
            clsWaterMarker WaterMarker = new clsWaterMarker();

            foreach(clsImageItem item in images)
            {
                WaterMarker.CreateAndInsertWaterMark(item, WaterMark);
            }
        }
Beispiel #4
0
        private void CreateOrUpdateImageWaterMark(Bitmap img = null)
        {
            if (img != null)
            {
                if (imgWM == null)
                {
                    imgWM = new clsImageWaterMark();
                }
                imgWM.ImgWaterMark = img;
            }
            if (imgWM != null)
            {
                imgWM.HasTransparentColor = WaterMarkHasTransparentColor;
                imgWM.TransparentColor = lblWMTransparentColor.BackColor;
                imgWM.Transparency = (int)nudTransparency.Value;
                imgWM.Layout = GetSelectedLayout();
                imgWM.OffSet.Width = (int)nudOffSetX.Value;
                imgWM.OffSet.Height = (int)nudOffSetY.Value;
                imgWM.Columns = (int)nudColumns.Value;
                imgWM.Rows = (int)nudRows.Value;

                SelectImageFromGrid();
                EnableDisableButtons(true);
            }
            else
            {
                EnableDisableButtons(false);
            }
        }
        private void DrawWaterMarkRepetition(ref clsImageWaterMark WM, Size NewWMSize, ImageAttributes imgAttrib)
        {
            Bitmap img = new Bitmap(NewWMSize.Width, NewWMSize.Height);
            Size aux = new Size();
            Size gap = new Size();
            double ratioWidth = ((double)NewWMSize.Width / (double)(WM.ImgWaterMark.Width * WM.Columns));
            double ratioHeight = ((double)NewWMSize.Height / (double)(WM.ImgWaterMark.Height * WM.Rows));

            //NewSize.Width = ImgSize.Width;
            //NewSize.Height = (int)(((double)ImgSize.Width / (double)WMSize.Width) * (double)WMSize.Height);

            if (ratioWidth > ratioHeight)
            {
                aux.Height = (int)((double)WM.Height * (double)ratioHeight);
                aux.Width = (int)((double)WM.Width * ((double)aux.Height / (double)WM.Height));
            }
            else
            {
                aux.Width = (int)((double)WM.Width * (double)ratioWidth);
                aux.Height = (int)((double)WM.Height * ((double)aux.Width / (double)WM.Width));
            }

            gap.Width = (int)((NewWMSize.Width - (aux.Width * WM.Columns)) / WM.Columns);
            gap.Height = (int)((NewWMSize.Height - (aux.Height * WM.Rows)) / WM.Rows);

            Graphics grPiece = Graphics.FromImage(img);
            int posX = 0;
            int posY;
            for (int x = 0; x < WM.Columns; x++)
            {
                posY = 0;
                for (int y = 0; y < WM.Rows; y++)
                {

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

                    posY += gap.Height + aux.Height;
                }
                posX += gap.Width + aux.Width;
            }
            WM.ImgWaterMark = img;
        }
        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;
        }