protected virtual Rectangle GetLargestInset(Rectangle sourceRect, float desiredAspect, AnchorLocation anchorLocation) { Rectangle width = new Rectangle(); float single = (float)sourceRect.Width / (float)sourceRect.Height; float single1 = desiredAspect / single; if (single <= desiredAspect) { width.Width = sourceRect.Width; width.Height = (int)((float)sourceRect.Height / single1); } else { width.Width = (int)((float)sourceRect.Width * single1); width.Height = sourceRect.Height; } RectangleUtil.PositionRectangle(anchorLocation, sourceRect, ref width); return(width); }
private Rectangle GetWatermarkArea(Image inputImage, Image watermarkImage) { Rectangle rectangle = new Rectangle(Point.Empty, inputImage.Size); Rectangle rectangle1 = new Rectangle(Point.Empty, watermarkImage.Size); RectangleUtil.PositionRectangle(base.AnchorLocation, rectangle, ref rectangle1); int width = (int)((float)inputImage.Width * 0.01f); int height = (int)((float)inputImage.Height * 0.01f); switch (base.AnchorLocation) { case AnchorLocation.LeftTop: { rectangle1.Offset(width, height); return(rectangle1); } case AnchorLocation.MiddleTop: { rectangle1.Offset(0, height); return(rectangle1); } case AnchorLocation.RightTop: { rectangle1.Offset(-width, height); return(rectangle1); } case AnchorLocation.LeftMiddle: { rectangle1.Offset(width, 0); return(rectangle1); } case AnchorLocation.Middle: { return(rectangle1); } case AnchorLocation.RightMiddle: { rectangle1.Offset(-width, 0); return(rectangle1); } case AnchorLocation.LeftBottom: { rectangle1.Offset(width, -height); return(rectangle1); } case AnchorLocation.MiddleBottom: { rectangle1.Offset(0, -height); return(rectangle1); } case AnchorLocation.RightBottom: { rectangle1.Offset(-width, -height); return(rectangle1); } default: { return(rectangle1); } } }
protected virtual Rectangle GetWatermarkArea(Graphics graphics, Image inputImage, out Font watermarkFont) { int[] numArray = new int[] { 16, 14, 12, 10, 8, 6, 4, 3, 2, 1 }; watermarkFont = null; Size empty = Size.Empty; for (int i = 0; i < (int)numArray.Length; i++) { watermarkFont = new Font("arial", (float)numArray[i], FontStyle.Bold); SizeF sizeF = graphics.MeasureString(this.Text, watermarkFont); empty = sizeF.ToSize(); if ((double)empty.Width < (double)inputImage.Width * 0.8) { break; } } Rectangle rectangle = new Rectangle(Point.Empty, inputImage.Size); Rectangle rectangle1 = new Rectangle(Point.Empty, empty); RectangleUtil.PositionRectangle(base.AnchorLocation, rectangle, ref rectangle1); int width = (int)((float)inputImage.Width * 0.01f); int height = (int)((float)inputImage.Height * 0.01f); switch (base.AnchorLocation) { case AnchorLocation.LeftTop: { rectangle1.Offset(width, height); return(rectangle1); } case AnchorLocation.MiddleTop: { rectangle1.Offset(0, height); return(rectangle1); } case AnchorLocation.RightTop: { rectangle1.Offset(-width, height); return(rectangle1); } case AnchorLocation.LeftMiddle: { rectangle1.Offset(width, 0); return(rectangle1); } case AnchorLocation.Middle: { return(rectangle1); } case AnchorLocation.RightMiddle: { rectangle1.Offset(-width, 0); return(rectangle1); } case AnchorLocation.LeftBottom: { rectangle1.Offset(width, -height); return(rectangle1); } case AnchorLocation.MiddleBottom: { rectangle1.Offset(0, -height); return(rectangle1); } case AnchorLocation.RightBottom: { rectangle1.Offset(-width, -height); return(rectangle1); } default: { return(rectangle1); } } }