public ImageResolution GetComputedResolution(ImageResolution mainImageResolution, ImageResolution scaledImageResolution)
        {
            if (mainImageResolution == null || scaledImageResolution == null)
            {
                throw new ArgumentNullException();
            }
            var result = new ImageResolution();

            if (PropertyDimension == ImageScaleDimension.Combined)
            {
                result.Width  = mainImageResolution.Width * Value;
                result.Height = mainImageResolution.Height * Value;
            }
            else if (PropertyDimension == ImageScaleDimension.Width)
            {
                result.Width  = mainImageResolution.Width * Value;
                result.Height = scaledImageResolution.Height * mainImageResolution.Width * Value / scaledImageResolution.Width;
            }
            else if (PropertyDimension == ImageScaleDimension.Height)
            {
                result.Height = mainImageResolution.Height * Value;
                result.Width  = scaledImageResolution.Width * mainImageResolution.Height * Value / scaledImageResolution.Height;
            }
            else
            {
                throw new NotImplementedException();
            }
            return(result);
        }
Exemple #2
0
 public AbsoluteImageMargin GetComputedMargin(ImageResolution imageResolution)
 {
     if (imageResolution == null)
     {
         throw new ArgumentNullException();
     }
     return(new AbsoluteImageMargin()
     {
         Top = imageResolution.Height * Top,
         Right = imageResolution.Width * Right,
         Bottom = imageResolution.Height * Bottom,
         Left = imageResolution.Width * Left
     });
 }
Exemple #3
0
 public AbsoluteImageMargin GetComputedMargin(ImageResolution imageResolution)
 {
     return(this);
 }
 public ImagePosition GetWatermarkPosition(ImageResolution imageResolution, ImageResolution watermarkResolution, AbsoluteImageMargin margin)
 {
     if (margin != null && imageResolution != null && watermarkResolution != null)
     {
         var resultPosition = new ImagePosition();
         if (Alignment == ImageAlignment.TopLeft)
         {
             resultPosition.FirstPoint  = new PointF(margin.Left, margin.Top);
             resultPosition.SecondPoint = new PointF(watermarkResolution.Width + margin.Left, margin.Top);
             resultPosition.ThirdPoint  = new PointF(margin.Left, watermarkResolution.Height + margin.Top);
         }
         else if (Alignment == ImageAlignment.TopRight)
         {
             resultPosition.FirstPoint  = new PointF(imageResolution.Width - margin.Right - watermarkResolution.Width, margin.Top);
             resultPosition.SecondPoint = new PointF(imageResolution.Width - margin.Right, margin.Top);
             resultPosition.ThirdPoint  = new PointF(imageResolution.Width - margin.Right - watermarkResolution.Width, watermarkResolution.Height + margin.Top);
         }
         else if (Alignment == ImageAlignment.BottomLeft)
         {
             resultPosition.FirstPoint  = new PointF(margin.Left, imageResolution.Height - watermarkResolution.Height - margin.Bottom);
             resultPosition.SecondPoint = new PointF(watermarkResolution.Width + margin.Left, imageResolution.Height - watermarkResolution.Height - margin.Bottom);
             resultPosition.ThirdPoint  = new PointF(margin.Left, imageResolution.Height - margin.Bottom);
         }
         else if (Alignment == ImageAlignment.BottomRight)
         {
             resultPosition.FirstPoint  = new PointF(imageResolution.Width - watermarkResolution.Width - margin.Right, imageResolution.Height - watermarkResolution.Height - margin.Bottom);
             resultPosition.SecondPoint = new PointF(imageResolution.Width - margin.Right, imageResolution.Height - watermarkResolution.Height - margin.Bottom);
             resultPosition.ThirdPoint  = new PointF(imageResolution.Width - watermarkResolution.Width - margin.Right, imageResolution.Height - margin.Bottom);
         }
         else if (Alignment == ImageAlignment.Top)
         {
             resultPosition.FirstPoint  = new PointF((imageResolution.Width / 2) - (watermarkResolution.Width / 2), margin.Top);
             resultPosition.SecondPoint = new PointF((imageResolution.Width / 2) + (watermarkResolution.Width / 2), margin.Top);
             resultPosition.ThirdPoint  = new PointF((imageResolution.Width / 2) - (watermarkResolution.Width / 2), margin.Top + watermarkResolution.Height);
         }
         else if (Alignment == ImageAlignment.Bottom)
         {
             resultPosition.FirstPoint  = new PointF((imageResolution.Width / 2) - (watermarkResolution.Width / 2), imageResolution.Height - margin.Bottom - watermarkResolution.Height);
             resultPosition.SecondPoint = new PointF((imageResolution.Width / 2) + (watermarkResolution.Width / 2), imageResolution.Height - margin.Bottom - watermarkResolution.Height);
             resultPosition.ThirdPoint  = new PointF((imageResolution.Width / 2) - (watermarkResolution.Width / 2), imageResolution.Height - margin.Bottom);
         }
         else if (Alignment == ImageAlignment.Left)
         {
             resultPosition.FirstPoint  = new PointF(margin.Left, (imageResolution.Height / 2) - (watermarkResolution.Height / 2));
             resultPosition.SecondPoint = new PointF(margin.Left + watermarkResolution.Width, (imageResolution.Height / 2) - (watermarkResolution.Height / 2));
             resultPosition.ThirdPoint  = new PointF(margin.Left, (imageResolution.Height / 2) + (watermarkResolution.Height / 2));
         }
         else if (Alignment == ImageAlignment.Right)
         {
             resultPosition.FirstPoint  = new PointF(imageResolution.Width - margin.Right - watermarkResolution.Width, (imageResolution.Height / 2) - (watermarkResolution.Height / 2));
             resultPosition.SecondPoint = new PointF(imageResolution.Width - margin.Right, (imageResolution.Height / 2) - (watermarkResolution.Height / 2));
             resultPosition.ThirdPoint  = new PointF(imageResolution.Width - margin.Right - watermarkResolution.Width, (imageResolution.Height / 2) + (watermarkResolution.Height / 2));
         }
         else if (Alignment == ImageAlignment.Center)
         {
             resultPosition.FirstPoint  = new PointF((imageResolution.Width / 2) - (watermarkResolution.Width / 2), (imageResolution.Height / 2) - (watermarkResolution.Height / 2));
             resultPosition.SecondPoint = new PointF((imageResolution.Width / 2) + (watermarkResolution.Width / 2), (imageResolution.Height / 2) - (watermarkResolution.Height / 2));
             resultPosition.ThirdPoint  = new PointF((imageResolution.Width / 2) - (watermarkResolution.Width / 2), (imageResolution.Height / 2) + (watermarkResolution.Height / 2));
         }
         else
         {
             throw new NotImplementedException();
         }
         return(resultPosition);
     }
     throw new ArgumentException();
 }