Ejemplo n.º 1
0
 public static Image AddCopyrightText(Image originImage, string copyrightText, CopyrightPosition position)
 {
     return(AddCopyrightText(originImage, copyrightText, Color.FromArgb(153, 0, 0, 0), Color.FromArgb(153, 255, 255, 255), null, position, 0.05, 1, 1, "Arial", FontStyle.Regular,
                             72f, 72f));
 }
Ejemplo n.º 2
0
 private static CopyrightHorizontalPosition GetHorizentalPosition(CopyrightPosition pos)
 {
     // Mask: 000 111
     return((CopyrightHorizontalPosition)((char)pos & (char)0x07));
 }
Ejemplo n.º 3
0
 private static CopyrightVerticalPosition GetVerticalPosition(CopyrightPosition pos)
 {
     // Mask: 111 000
     return((CopyrightVerticalPosition)((char)pos & (char)0x38));
 }
Ejemplo n.º 4
0
        public static Image AddCopyrightText(Image originImage, string copyrightText, Color shadowColor, Color color, int[] fontSizes,
                                             CopyrightPosition position = CopyrightPosition.BottomCenter,
                                             double marginPercent       = 0.05, int shadowOffsetX = 1, int shadowOffsetY = 1, string fontFamily = "Arial", FontStyle fontStyle = FontStyle.Regular,
                                             float xDpi = 72f, float yDpi = 72f)
        {
            // Try to find the possible max size of the Copyright message
            Graphics g = Graphics.FromImage(originImage);

            if (fontSizes == null || fontSizes.Length <= 0)
            {
                fontSizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
            }

            int fontSize = 0;

            if (fontSizes.Length > 1)
            {
                fontSize = FindAvailableMaxTextSize(fontSizes, fontFamily, fontStyle, copyrightText, g, originImage.Width, originImage.Height);
            }
            else
            {
                fontSize = fontSizes[0];
            }

            Font  font = new Font(fontFamily, fontSize, fontStyle);
            SizeF size = new SizeF();

            size = g.MeasureString(copyrightText, font);
            g.Dispose();

            // Compute x and y
            float           x = 0, y = 0;
            StringAlignment alignment = StringAlignment.Center;

            switch (GetHorizentalPosition(position))
            {
            case CopyrightHorizontalPosition.Left:
                x         = (int)(originImage.Width * marginPercent);
                alignment = StringAlignment.Near;
                break;

            case CopyrightHorizontalPosition.Center:
                x         = originImage.Width / 2;
                alignment = StringAlignment.Center;
                break;

            case CopyrightHorizontalPosition.Right:
                x         = (originImage.Width - ((int)(originImage.Width * marginPercent)));
                alignment = StringAlignment.Far;
                break;

            default:
                break;
            }

            switch (GetVerticalPosition(position))
            {
            case CopyrightVerticalPosition.Top:
                y = (int)(originImage.Height * marginPercent);
                break;

            case CopyrightVerticalPosition.Middle:
                y = originImage.Height / 2;
                break;

            case CopyrightVerticalPosition.Bottom:
                y = (originImage.Height - ((int)(originImage.Height * marginPercent))) - (size.Height / 2);
                break;

            default:
                break;
            }

            return(AddCopyrightText(originImage, copyrightText, shadowColor, color, x, y, fontSizes, shadowOffsetX, shadowOffsetY, fontFamily, fontStyle, alignment, xDpi, yDpi));
        }