Ejemplo n.º 1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="width">缩放后的宽度</param>
 /// <param name="height">缩放后的高度</param>
 /// <param name="resizeMethod">缩放方式</param>
 /// <param name="anchorLocation">如需裁剪时,矩形选区停靠位置</param>
 public ResizeFilter(int width, int height, ResizeMethod resizeMethod, AnchorLocation anchorLocation)
 {
     this.TargetSize         = new Size(width, height);
     this.ResizeMethod       = resizeMethod;
     this.AnchorLocation     = anchorLocation;
     this.InterpoliationMode = InterpolationMode.HighQualityBicubic;
     this.SmoothingMode      = SmoothingMode.HighQuality;
 }
Ejemplo n.º 2
0
 public ResizeFilter(int width, int height, ResizeMethod resizeMethod, AnchorLocation anchorLocation)
 {
     this.TargetSize = new Size(width, height);
     this.ResizeMethod = resizeMethod;
     this.AnchorLocation = anchorLocation;
     this.InterpoliationMode = InterpolationMode.HighQualityBicubic;
     this.SmoothingMode = SmoothingMode.HighQuality;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 按照停靠位置定位矩形选区(destRect)在矩形容器(sourceRect)中的位置
        /// </summary>
        /// <param name="anchorLocation">矩形选区停靠位置</param>
        /// <param name="sourceRect">矩形容器</param>
        /// <param name="destRect">矩形选区</param>
        public static void PositionRectangle(AnchorLocation anchorLocation, Rectangle sourceRect, ref Rectangle destRect)
        {
            // Position the rectangle based on the anchor location
            switch (anchorLocation)
            {
            // Top -------------------------

            case AnchorLocation.LeftTop:
                destRect.X = destRect.Y = 0;
                break;

            case AnchorLocation.MiddleTop:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = 0;
                break;

            case AnchorLocation.RightTop:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = 0;
                break;


            // Middle -------------------------

            case AnchorLocation.LeftMiddle:
                destRect.X = 0;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                break;

            case AnchorLocation.Middle:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                break;

            case AnchorLocation.RightMiddle:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                break;


            // Bottom

            case AnchorLocation.LeftBottom:
                destRect.X = 0;
                destRect.Y = sourceRect.Height - destRect.Height;
                break;

            case AnchorLocation.MiddleBottom:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = sourceRect.Height - destRect.Height;
                break;

            case AnchorLocation.RightBottom:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = sourceRect.Height - destRect.Height;
                break;
            }
        }
Ejemplo n.º 4
0
		public static void PositionRectangle(AnchorLocation anchorLocation, Rectangle sourceRect, ref Rectangle destRect)
		{
			// Position the rectangle based on the anchor location
			switch (anchorLocation)
			{
				// Top -------------------------

				case Filters.AnchorLocation.TopLeft:
					destRect.X = destRect.Y = 0;
					break;

				case Filters.AnchorLocation.TopMiddle:
					destRect.X = (sourceRect.Width - destRect.Width) / 2;
					destRect.Y = 0;
					break;

				case Filters.AnchorLocation.TopRight:
					destRect.X = sourceRect.Width - destRect.Width;
					destRect.Y = 0;
					break;

				// Middle -------------------------

				case Filters.AnchorLocation.MiddleLeft:
					destRect.X = 0;
					destRect.Y = (sourceRect.Height - destRect.Height) / 2;
					break;

				case Filters.AnchorLocation.Middle:
					destRect.X = (sourceRect.Width - destRect.Width) / 2;
					destRect.Y = (sourceRect.Height - destRect.Height) / 2;
					break;

				case Filters.AnchorLocation.MiddleRight:
					destRect.X = sourceRect.Width - destRect.Width;
					destRect.Y = (sourceRect.Height - destRect.Height) / 2;
					break;

				// Bottom

				case Filters.AnchorLocation.BottomLeft:
					destRect.X = 0;
					destRect.Y = sourceRect.Height - destRect.Height;
					break;

				case Filters.AnchorLocation.BottomMiddle:
					destRect.X = (sourceRect.Width - destRect.Width) / 2;
					destRect.Y = sourceRect.Height - destRect.Height;
					break;

				case Filters.AnchorLocation.BottomRight:
					destRect.X = sourceRect.Width - destRect.Width;
					destRect.Y = sourceRect.Height - destRect.Height;
					break;
			}

		}
Ejemplo n.º 5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CropFilter"/> class.
		/// </summary>
		/// <param name="shrinkFactor">The shrink factor.</param>
		/// <param name="anchor">The anchor.</param>
		public CropFilter(double shrinkFactor, AnchorLocation anchor)
		{
			if (0 > shrinkFactor || shrinkFactor > 1)
				throw new ArgumentException("Shrink factor must be between 0 and 1");

			this.ShrinkFactor = shrinkFactor;
			this.Anchor = anchor;
			this._cropMode = CropMode.ShrinkFactor;
		}
Ejemplo n.º 6
0
        public static void PositionRectangle(AnchorLocation anchorLocation, Rectangle sourceRect, ref Rectangle destRect)
        {
            // Position the rectangle based on the anchor location
            switch (anchorLocation)
            {
            // Top -------------------------

            case Filters.AnchorLocation.TopLeft:
                destRect.X = destRect.Y = 0;
                break;

            case Filters.AnchorLocation.TopMiddle:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = 0;
                break;

            case Filters.AnchorLocation.TopRight:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = 0;
                break;

            // Middle -------------------------

            case Filters.AnchorLocation.MiddleLeft:
                destRect.X = 0;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                break;

            case Filters.AnchorLocation.Middle:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                break;

            case Filters.AnchorLocation.MiddleRight:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                break;

            // Bottom

            case Filters.AnchorLocation.BottomLeft:
                destRect.X = 0;
                destRect.Y = sourceRect.Height - destRect.Height;
                break;

            case Filters.AnchorLocation.BottomMiddle:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = sourceRect.Height - destRect.Height;
                break;

            case Filters.AnchorLocation.BottomRight:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = sourceRect.Height - destRect.Height;
                break;
            }
        }
Ejemplo n.º 7
0
        public static void PositionRectangle(AnchorLocation anchorLocation, Rectangle sourceRect, ref Rectangle destRect)
        {
            switch (anchorLocation)
            {
            case AnchorLocation.LeftTop:
                destRect.X = (destRect.Y = 0);
                return;

            case AnchorLocation.MiddleTop:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = 0;
                return;

            case AnchorLocation.RightTop:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = 0;
                return;

            case AnchorLocation.LeftMiddle:
                if (true)
                {
                }
                destRect.X = 0;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                return;

            case AnchorLocation.Middle:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                return;

            case AnchorLocation.RightMiddle:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = (sourceRect.Height - destRect.Height) / 2;
                return;

            case AnchorLocation.LeftBottom:
                destRect.X = 0;
                destRect.Y = sourceRect.Height - destRect.Height;
                return;

            case AnchorLocation.MiddleBottom:
                destRect.X = (sourceRect.Width - destRect.Width) / 2;
                destRect.Y = sourceRect.Height - destRect.Height;
                return;

            case AnchorLocation.RightBottom:
                destRect.X = sourceRect.Width - destRect.Width;
                destRect.Y = sourceRect.Height - destRect.Height;
                return;

            default:
                return;
            }
        }
Ejemplo n.º 8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ResizeFilter"/> class.
		/// </summary>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		/// <param name="method">The resize method.</param>
		/// <param name="anchorLocation">The anchor location, for when cropping is used.</param>
		public ResizeFilter(int width, int height, ResizeMethod method, AnchorLocation anchorLocation, Axis? constrainAxis = null)
		{
			this.TargetSize = new Size(width, height);
			this.ResizeMethod = method;
			this.AnchorLocation = anchorLocation;
			this.Resolution = Resolution.Screen;
			this.CompositingQuality = CompositingQuality.HighQuality;
			this.InterpoliationMode = InterpolationMode.HighQualityBicubic;
			this.BackgroundColour = Color.White;
            this.ConstrainAxis = constrainAxis;
		}
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CropFilter"/> class.
        /// </summary>
        /// <param name="shrinkFactor">The shrink factor.</param>
        /// <param name="anchor">The anchor.</param>
        public CropFilter(double shrinkFactor, AnchorLocation anchor)
        {
            if (0 > shrinkFactor || shrinkFactor > 1)
            {
                throw new ArgumentException("Shrink factor must be between 0 and 1");
            }

            this.ShrinkFactor = shrinkFactor;
            this.Anchor       = anchor;
            this._cropMode    = CropMode.ShrinkFactor;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResizeFilter"/> class.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="method">The resize method.</param>
 /// <param name="anchorLocation">The anchor location, for when cropping is used.</param>
 public ResizeFilter(int width, int height, ResizeMethod method, AnchorLocation anchorLocation, Axis?constrainAxis = null)
 {
     this.TargetSize         = new Size(width, height);
     this.ResizeMethod       = method;
     this.AnchorLocation     = anchorLocation;
     this.Resolution         = Resolution.Screen;
     this.CompositingQuality = CompositingQuality.HighQuality;
     this.InterpoliationMode = InterpolationMode.HighQualityBicubic;
     this.BackgroundColour   = Color.White;
     this.ConstrainAxis      = constrainAxis;
 }
Ejemplo n.º 11
0
    /*
     * Gets the position of the top left corner of this object relative to the anchor point. Default is center
     */
    public Vector3 GetAnchorOffset(float width, float height, AnchorLocation anchor)
    {
        Vector3 position = new Vector3();

        switch (m_anchorPoint)
        {
        case AnchorLocation.LEFT:
            position.x = (bRotated) ? 0.0f : width * 0.5f;
            position.y = (bRotated) ? -height * 0.5f : 0.0f;
            break;

        case AnchorLocation.TOP:
            position.x = (bRotated) ? -width * 0.5f : 0.0f;
            position.y = (bRotated) ? 0.0f : -height * 0.5f;
            break;

        case AnchorLocation.RIGHT:
            position.x = (bRotated) ? 0.0f : -width * 0.5f;
            position.y = (bRotated) ? height * 0.5f : 0.0f;
            break;

        case AnchorLocation.BOTTOM:
            position.x = (bRotated) ? width * 0.5f : 0.0f;
            position.y = (bRotated) ? 0.0f : height * 0.5f;
            break;

        case AnchorLocation.TOP_LEFT:
            position.x = (bRotated) ? -width * 0.5f : width * 0.5f;
            position.y = (bRotated) ? -height * 0.5f : -height * 0.5f;
            break;

        case AnchorLocation.TOP_RIGHT:
            position.x = (bRotated) ? -width * 0.5f : -width * 0.5f;
            position.y = (bRotated) ? height * 0.5f : -height * 0.5f;
            break;

        case AnchorLocation.BOTTOM_LEFT:
            position.x = (bRotated) ? width * 0.5f : width * 0.5f;
            position.y = (bRotated) ? -height * 0.5f : height * 0.5f;
            break;

        case AnchorLocation.BOTTOM_RIGHT:
            position.x = (bRotated) ? width * 0.5f : -width * 0.5f;
            position.y = (bRotated) ? height * 0.5f : height * 0.5f;
            break;

        case AnchorLocation.CENTER:
            position.x = 0.0f;
            position.y = 0.0f;
            break;
        }

        return(position);
    }
Ejemplo n.º 12
0
 public void RemoveLine(Line l, AnchorLocation al)
 {
     if (al == AnchorLocation.Front)
     {
         l.FrontAnchor = null;
     }
     else
     {
         l.BackAnchor = null;
     }
     __lines.Remove(l);
 }
Ejemplo n.º 13
0
 public void AddLine(Line l, AnchorLocation al)
 {
     __lines.Add(l);
     if (al == AnchorLocation.Front)
     {
         l.FrontAnchor = this;
     }
     else
     {
         l.BackAnchor = this;
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TextWatermarkFilter"/> class.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="fontName">Name of the font.</param>
 /// <param name="fontSize">Size of the font.</param>
 /// <param name="anchorLocation">The anchor location.</param>
 /// <param name="style">The font style.</param>
 public TextWatermarkFilter(string text,
                            string fontName = "Arial",
                            int fontSize    = 24,
                            AnchorLocation anchorLocation = Filters.AnchorLocation.BottomRight,
                            FontStyle style = FontStyle.Regular)
 {
     this.Text           = text;
     this.FontName       = fontName;
     this.FontSize       = fontSize;
     this.AnchorLocation = anchorLocation;
     this.FontStyle      = style;
     this.TextColour     = Color.White;
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="TextWatermarkFilter"/> class.
		/// </summary>
		/// <param name="text">The text.</param>
		/// <param name="fontName">Name of the font.</param>
		/// <param name="fontSize">Size of the font.</param>
		/// <param name="anchorLocation">The anchor location.</param>
		/// <param name="style">The font style.</param>
		public TextWatermarkFilter(string text, 
			string fontName = "Arial", 
			int fontSize = 24,
			AnchorLocation anchorLocation = Filters.AnchorLocation.BottomRight,			
			FontStyle style = FontStyle.Regular)
		{
			this.Text = text;
			this.FontName = fontName;
			this.FontSize = fontSize;
			this.AnchorLocation = anchorLocation;			
			this.FontStyle = style;
			this.TextColour = Color.White;
		}
Ejemplo n.º 16
0
        private static MemoryStream ToThumbnailImage(byte[] image, AnchorLocation anchor)
        {
            var thumbnailImage = new MemoryStream();

            ImageBuilder.Current.Build(new ImageJob(new MemoryStream(image), thumbnailImage, new Instructions()
            {
                Width  = 256,
                Height = 256,
                Mode   = FitMode.Crop,
                Scale  = ScaleMode.Both,
                Anchor = anchor
            }));
            return(thumbnailImage);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Resizes the image.
        /// </summary>
        /// <param name="inputFilename">The input filename.</param>
        /// <param name="outputFilename">The output filename.</param>
        /// <param name="width">The desired width of the output image.</param>
        /// <param name="height">The desired height of the output image.</param>
        /// <param name="method">The resize calculation method</param>
        /// <param name="anchorLocation">The anchor location.</param>
        /// <param name="jpegQuality">The JPEG quality.</param>
        /// <param name="outputFormat">The output format.</param>
        public static void ResizeImage(string inputFilename,
                                       string outputFilename,
                                       int width,
                                       int height,
                                       ResizeMethod method           = ResizeMethod.KeepAspectRatio,
                                       AnchorLocation anchorLocation = AnchorLocation.Middle,
                                       long jpegQuality             = 80L,
                                       ImageFormatType outputFormat = ImageFormatType.Default)
        {
            ImageProcessor processor = new ImageProcessor(new ResizeFilter(width, height, method, anchorLocation));
            ResizeFilter   filter    = new ResizeFilter(width, height, method, anchorLocation);

            processor.JpegCompression = jpegQuality;
            processor.OutputFormat    = outputFormat;

            processor.ProcessImage(inputFilename, outputFilename);
        }
Ejemplo n.º 18
0
 public static void PositionRectangle(AnchorLocation anchorLocation, Rectangle sourceRect, ref Rectangle destRect)
 {
     switch (anchorLocation)
     {
     case AnchorLocation.LeftTop:
         destRect.X = (destRect.Y = 0);
         return;
     case AnchorLocation.MiddleTop:
         destRect.X = (sourceRect.Width - destRect.Width) / 2;
         destRect.Y = 0;
         return;
     case AnchorLocation.RightTop:
         destRect.X = sourceRect.Width - destRect.Width;
         destRect.Y = 0;
         return;
     case AnchorLocation.LeftMiddle:
         destRect.X = 0;
         destRect.Y = (sourceRect.Height - destRect.Height) / 2;
         return;
     case AnchorLocation.Middle:
         destRect.X = (sourceRect.Width - destRect.Width) / 2;
         destRect.Y = (sourceRect.Height - destRect.Height) / 2;
         return;
     case AnchorLocation.RightMiddle:
         destRect.X = sourceRect.Width - destRect.Width;
         destRect.Y = (sourceRect.Height - destRect.Height) / 2;
         return;
     case AnchorLocation.LeftBottom:
         destRect.X = 0;
         destRect.Y = sourceRect.Height - destRect.Height;
         return;
     case AnchorLocation.MiddleBottom:
         destRect.X = (sourceRect.Width - destRect.Width) / 2;
         destRect.Y = sourceRect.Height - destRect.Height;
         return;
     case AnchorLocation.RightBottom:
         destRect.X = sourceRect.Width - destRect.Width;
         destRect.Y = sourceRect.Height - destRect.Height;
         return;
     default:
         return;
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Add a control to the corner anchor.
        /// </summary>
        /// <param name="transform">The control to add.</param>
        /// <param name="anchor">The corner of the screen to anchor the control to.</param>
        /// <param name="margin">The margin of the control.</param>
        public void AddChild(Transform transform, AnchorLocation anchor, Rectangle margin)
        {
            AnchorLayoutControl anchorControl = new AnchorLayoutControl
            {
                Control = transform,
                Anchor  = anchor,
                Margin  = margin
            };

            lock (_controls)
            {
                _controls.Add(anchorControl);
            }

            // Hook up to event.
            transform.OnResize += _updateEvent;

            ApplyLogic();
            base.AddChild(transform);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageWatermarkFilter"/> class.
 /// </summary>
 /// <param name="watermarkImage">The watermark image.</param>
 /// <param name="anchorLocation">The anchor location.</param>
 public ImageWatermarkFilter(Image watermarkImage, AnchorLocation anchorLocation = AnchorLocation.BottomRight)
 {
     this.WatermarkImage = watermarkImage;
     this.AnchorLocation = anchorLocation;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// 按照期望的宽高比获取sourceRect中最大矩形区域
        /// </summary>
        /// <param name="sourceRect">源矩形区域</param>
        /// <param name="desiredAspect">期望的宽高比</param>
        /// <param name="anchorLocation">矩形选区停靠位置</param>
        /// <returns>返回在sourceRect内满足desiredAspect的最大矩形区域</returns>
        protected virtual Rectangle GetLargestInset(Rectangle sourceRect, float desiredAspect, AnchorLocation anchorLocation)
        {
            Rectangle destRect = default(Rectangle);

            float sourceAspect = (float)sourceRect.Width / (float)sourceRect.Height;
            float ratioScale   = desiredAspect / sourceAspect;

            if (sourceAspect > desiredAspect)
            {
                destRect.Width  = (int)((float)sourceRect.Width * ratioScale);
                destRect.Height = sourceRect.Height;
            }
            else
            {
                destRect.Width  = sourceRect.Width;
                destRect.Height = (int)((float)sourceRect.Height / ratioScale);
            }

            RectangleUtil.PositionRectangle(anchorLocation, sourceRect, ref destRect);

            return(destRect);
        }
Ejemplo n.º 22
0
        private void PaintTail(AnchorLocation location, double W, double H, DrawingContext drawingContext)
        {
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure pathFigure = new PathFigure();
            PathSegmentCollection segmentCollection = new PathSegmentCollection();

            double radius = CornerRadius.BottomLeft;
            Size size = new Size(radius, radius);
            Point startPoint = GetDrawStartPoint(location);

            switch (location)
            {
                case AnchorLocation.None:
                    W = W + startPoint.X;
                    H = H + startPoint.Y;

                    pathFigure.StartPoint = new Point(startPoint.X, radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(radius, H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(W - radius, H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(W, H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(W, radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.LeftTop:

                    if (H * 0.15 > radius)
                    {
                        pathFigure.StartPoint = new Point(startPoint.X, radius + startPoint.Y);
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H * 0.15) });
                    }
                    else
                        pathFigure.StartPoint = new Point(startPoint.X, H * 0.15 + startPoint.Y);
                    segmentCollection.Add(new LineSegment() { Point = AnchorPoint.Y < 0 ? new Point(0, 0) : new Point(0, AnchorPoint.Y + startPoint.Y) }); ///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H * 0.35) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    if (H * 0.15 > radius)
                    {
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });
                    }
                    else
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + H * 0.15), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.LeftBottom:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H * 0.65) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(0, AnchorPoint.Y + startPoint.Y) });  ///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H * 0.85) });
                    if (H * 0.15 > radius)
                    {
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    }
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.TopLeft:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.35, startPoint.Y) });
                    segmentCollection.Add(new LineSegment() { Point = AnchorPoint.X < 0 ? new Point(0.0, 0.0) : new Point(AnchorPoint.X + startPoint.X, 0) });///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.15, startPoint.Y) });
                    if (W * 0.15 > radius)
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.TopRight:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    if (W * 0.15 > radius)
                    {
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.85, startPoint.Y) });
                    }
                    else
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W * 0.85, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(AnchorPoint.X + startPoint.X, 0) });///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.65, startPoint.Y) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.RightTop:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H * 0.35) });
                    segmentCollection.Add(new LineSegment() { Point = AnchorPoint.Y < 0 ? new Point(AnchorPoint.X + startPoint.X, 0) : new Point(AnchorPoint.X + startPoint.X, AnchorPoint.Y + startPoint.Y) });///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H * 0.15) });
                    if (H * 0.15 > radius)
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.RightBottom:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    if (H * 0.15 > radius)
                    {
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H * 0.85) });
                    }
                    else
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H * 0.85), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H * 0.85) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + AnchorPoint.X, AnchorPoint.Y + startPoint.Y) });///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H * 0.65) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.BottomLeft:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    if (W * 0.15 > radius)
                    {
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.15, startPoint.Y + H) });
                    }
                    else
                        segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W * 0.15, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = AnchorPoint.X < 0 ? new Point(0, AnchorPoint.Y + startPoint.Y) : new Point(AnchorPoint.X + startPoint.X, AnchorPoint.Y + startPoint.Y) });///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.35, startPoint.Y + H) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;

                case AnchorLocation.BottomRight:

                    pathFigure.StartPoint = new Point(startPoint.X, startPoint.Y + radius);
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X, startPoint.Y + H - radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + radius, startPoint.Y + H), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.65, startPoint.Y + H) });
                    segmentCollection.Add(new LineSegment() { Point = new Point(AnchorPoint.X + startPoint.X, AnchorPoint.Y + startPoint.Y) });///
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W * 0.85, startPoint.Y + H) });
                    if (W * 0.15 > radius)
                        segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y + H) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W, startPoint.Y + H - radius), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + W, startPoint.Y + radius) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X + W - radius, startPoint.Y), Size = size, RotationAngle = 90 });
                    segmentCollection.Add(new LineSegment() { Point = new Point(startPoint.X + radius, startPoint.Y) });
                    segmentCollection.Add(new ArcSegment() { Point = new Point(startPoint.X, startPoint.Y + radius), Size = size, RotationAngle = 90 });

                    break;
            }

            pathFigure.Segments = segmentCollection;
            pathGeometry.Figures = new PathFigureCollection() { pathFigure };

            drawingContext.DrawGeometry(Background, new Pen(BorderBrush, BorderThickness), pathGeometry);
        }
Ejemplo n.º 23
0
 protected virtual Rectangle GetLargestInset(Rectangle sourceRect, float desiredAspect, AnchorLocation anchorLocation)
 {
     Rectangle result = default(Rectangle);
     float num = (float)sourceRect.Width / (float)sourceRect.Height;
     float num2 = desiredAspect / num;
     if (num > desiredAspect)
     {
         result.Width = (int)((float)sourceRect.Width * num2);
         result.Height = sourceRect.Height;
     }
     else
     {
         result.Width = sourceRect.Width;
         result.Height = (int)((float)sourceRect.Height / num2);
     }
     RectangleUtil.PositionRectangle(anchorLocation, sourceRect, ref result);
     return result;
 }
Ejemplo n.º 24
0
 /*
  * Sets anchor point for frame
  */
 public void SetAnchor(AnchorLocation anchor)
 {
     m_anchorPoint = anchor;
     toggleUpdate  = true;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="watermarkImage">作为水印的图像文件</param>
 /// <param name="anchorLocation">水印在图像上的停靠位置 </param>
 /// <param name="opacity">不透明度</param>
 public ImageWatermarkFilter(Image watermarkImage, AnchorLocation anchorLocation, float opacity)
 {
     this.WatermarkImage = watermarkImage;
     base.AnchorLocation = anchorLocation;
     base.Opacity        = opacity;
 }
Ejemplo n.º 26
0
 public BalloonBorder()
     : base()
 {
     AnchorLocation = GetAnchorLocation();
 }
Ejemplo n.º 27
0
        public static async Task <HttpResponseMessage> ImageUpload(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "images/upload")] HttpRequestMessage req,
            [Table("Users")] IQueryable <User> users,
            [Table("CreateImageFromUrls")] IQueryable <CreateImageFromUrlsEntity> imageUrls,
            [Queue("create-image-from-urls")] ICollector <CreateImageFromUrlsRequest> queueItems,
            [Table("CreateImageFromUrls")] ICollector <CreateImageFromUrlsEntity> outImageUrlTable,
            [Table("PredictedInfo")] ICollector <PredictedInfo> outPredictedTable,
            TraceWriter log,
            Microsoft.Azure.WebJobs.ExecutionContext context)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // collect input
            dynamic data = await req.Content.ReadAsAsync <object>();

            string imageData          = data.image;
            ICollection <string> tags = data.tags.ToObject <List <string> >();
            string modelName          = data.modelName;

            log.Info($"modelName={modelName}tags={string.Join(",", tags)}, image={imageData}");

            var dataUrlReg = Regex.Match(imageData, @"data:image/(?<type>.+?);base64,(?<data>.+)");
            var image      = Convert.FromBase64String(dataUrlReg.Groups["data"].Value);
            var extension  = dataUrlReg.Groups["type"].Value;

            // client
            var CV_ProjectId     = Environment.GetEnvironmentVariable("CV_ProjectId");
            var CV_TrainingKey   = Environment.GetEnvironmentVariable("CV_TrainingKey");
            var CV_PredictionKey = Environment.GetEnvironmentVariable("CV_PredictionKey");
            var trainingApi      = new TrainingApi()
            {
                ApiKey = CV_TrainingKey
            };
            var predictionEndpoint = new PredictionEndpoint()
            {
                ApiKey = CV_PredictionKey
            };
            var projectId = Guid.Parse(CV_ProjectId);

            // collect user
            var user  = User.FromRequest(users, req, Thread.CurrentPrincipal);
            var iuser = user as IUser;

            // 既存のタグのみを受け付ける
            var existTags = await trainingApi.GetTagsAsync(projectId);

            tags = tags.Intersect(existTags.Select(x => x.Name)).ToList();

            // setup blob
            // https://docs.microsoft.com/ja-jp/azure/cosmos-db/table-storage-design-guide#log-tail-pattern
            var invertedTicks = string.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks);
            var blobName      = invertedTicks + "-" + Guid.NewGuid().ToString();

            var blockBlob          = CommonHelper.PhotoBlobReference(blobName);
            var blockBlobThumbnail = CommonHelper.PhotoThumbnailBlobReference(blobName);

            blockBlob.Properties.ContentType          = "image/jpeg";
            blockBlobThumbnail.Properties.ContentType = "image/jpeg";

            var url    = blockBlob.Uri.ToString();
            var source = "Upload";
            var key    = blockBlob.Name;

            log.Info($"pre upload. blobUri={url}");

            // XXX この辺りの一連の手続きをいい感じに関数分割してフロー処理できると可用性と変更影響範囲が良くなりそう
            // ただ、この程度の規模のサービスで1関数で同期的に処理する平易さ以上のメリットを得られるかは疑問

            // normalize image
            MemoryStream   normalizedImage = NormalizeImage(image);
            AnchorLocation anchor          = DetectFocusAnchor(log, normalizedImage, context.FunctionAppDirectory);

            log.Info($"Anchor: {anchor.ToString()}");
            MemoryStream thumbnailImage = ToThumbnailImage(image, anchor);

            // upload image
            normalizedImage.Position = 0;
            thumbnailImage.Position  = 0;
            await blockBlob.UploadFromStreamAsync(normalizedImage);

            await blockBlobThumbnail.UploadFromStreamAsync(thumbnailImage);

            log.Info($"after upload.");

            // queue image for training
            // 使用しているAPIの都合上、BLOBがアップロード後である必要がある
            TrainingImageLogic.AddImage(
                imageUrls, queueItems, outImageUrlTable, log,
                source, url, key, tags, user, modelName
                );
            log.Info($"after queue image data.");

            // predict image
            // https://docs.microsoft.com/ja-jp/azure/cognitive-services/custom-vision-service/csharp-tutorial
            var imageUrl = new ImageUrl()
            {
                Url = url
            };
            // XXX Storage emurator で通すならNgrock等の工夫が必要。単にDevelop用のStorage Accountを取ってしまった方が楽かも。
            var predictResult = await predictionEndpoint.PredictImageUrlAsync(projectId, imageUrl);

            log.Info($"after prediction.");
            var predicted = new PredictedInfo()
            {
                PartitionKey = source,
                RowKey       = key,
                Result       = predictResult,
                User         = user,
                ModelName    = modelName
            };

            outPredictedTable.Add(predicted);

            return(req.CreateJsonResponse(HttpStatusCode.OK, new
            {
                name = blockBlob.Name,
                url,
                result = predictResult
            }));
        }
Ejemplo n.º 28
0
		/// <summary>
		/// Resizes the image.
		/// </summary>
		/// <param name="inputFilename">The input filename.</param>
		/// <param name="outputFilename">The output filename.</param>
		/// <param name="width">The desired width of the output image.</param>
		/// <param name="height">The desired height of the output image.</param>
		/// <param name="method">The resize calculation method</param>
		/// <param name="anchorLocation">The anchor location.</param>
		/// <param name="jpegQuality">The JPEG quality.</param>
		/// <param name="outputFormat">The output format.</param>
		public static void ResizeImage(string inputFilename, 
			string outputFilename, 
			int width, 
			int height, 
			ResizeMethod method = ResizeMethod.KeepAspectRatio, 
			AnchorLocation anchorLocation = AnchorLocation.Middle,
			long jpegQuality = 80L, 
			ImageFormatType outputFormat = ImageFormatType.Default)
		{
			ImageProcessor processor = new ImageProcessor(new ResizeFilter(width, height, method, anchorLocation));
			ResizeFilter filter = new ResizeFilter(width, height, method, anchorLocation);

			processor.JpegCompression = jpegQuality;
			processor.OutputFormat = outputFormat;

			processor.ProcessImage(inputFilename, outputFilename);
		}
Ejemplo n.º 29
0
 public ImageWatermarkFilter(Image watermarkImage, AnchorLocation anchorLocation, float opacity)
 {
     this.WatermarkImage = watermarkImage;
     base.AnchorLocation = anchorLocation;
     base.Opacity = opacity;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Add a control to the corner anchor.
 /// </summary>
 /// <param name="control">The control to add.</param>
 /// <param name="anchor">The corner of the screen to anchor the control to.</param>
 public void AddChild(Transform control, AnchorLocation anchor)
 {
     AddChild(control, anchor, Rectangle.Empty);
 }
Ejemplo n.º 31
0
		public AnchorPane(Renderable2D control, AnchorLocation location)
		{
			this.Control = control;
			Location = location;	
		}
Ejemplo n.º 32
0
		public AnchorPane(AnchorLocation location)
			: this(null, location)
		{
		}
Ejemplo n.º 33
0
		// Define other methods and classes here
		/// <summary>
		/// Finds the largest rectangle which can fit inside sourceRect with the desired aspect ratio
		/// </summary>
		/// <param name="sourceRect">The container rectangle</param>
		/// <param name="desiredAspect">The desired aspect ratio</param>
		/// <param name="anchorLocation">The anchor location.</param>
		/// <returns>A Rectangle which represents the largest possible area that should be taken from the source image given the input parameters.</returns>
		public virtual Rectangle GetLargestInset(Rectangle sourceRect, float desiredAspect, AnchorLocation anchorLocation)
		{
			Rectangle destRect = default(Rectangle);

			float sourceAspect = (float)sourceRect.Width / (float)sourceRect.Height;
			float ratioScale = desiredAspect / sourceAspect;

			if (sourceAspect > desiredAspect)
			{
				destRect.Width = (int)((float)sourceRect.Width * ratioScale);
				destRect.Height = sourceRect.Height;
			}
			else
			{
				destRect.Width = sourceRect.Width;
				destRect.Height = (int)((float)sourceRect.Height / ratioScale);
			}

			RectangleUtil.PositionRectangle(anchorLocation, sourceRect, ref destRect);

			return destRect;
		}
Ejemplo n.º 34
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="watermarkImage">作为水印的图像文件</param>
 /// <param name="anchorLocation">水印在图像上的停靠位置 </param>
 public ImageWatermarkFilter(Image watermarkImage, AnchorLocation anchorLocation)
     : this(watermarkImage, anchorLocation, 0.6F)
 {
 }
Ejemplo n.º 35
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="watermarkImagePhysicalPath">作为水印的图像文件物理路径</param>
 /// <param name="anchorLocation">水印在图像上的停靠位置 </param>
 public ImageWatermarkFilter(string watermarkImagePhysicalPath, AnchorLocation anchorLocation)
     : this(watermarkImagePhysicalPath, anchorLocation, 0.6F)
 {
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="ImageWatermarkFilter"/> class.
		/// </summary>
		/// <param name="watermarkImagePath">The watermark image path.</param>
		/// <param name="anchorLocation">The anchor location.</param>
		public ImageWatermarkFilter(string watermarkImagePath, AnchorLocation anchorLocation = AnchorLocation.BottomRight)
			: this(Image.FromFile(watermarkImagePath), anchorLocation)
		{
		}
Ejemplo n.º 37
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="watermarkImagePhysicalPath">作为水印的图像文件物理路径</param>
 /// <param name="anchorLocation">水印在图像上的停靠位置 </param>
 /// <param name="opacity">不透明度</param>
 public ImageWatermarkFilter(string watermarkImagePhysicalPath, AnchorLocation anchorLocation, float opacity)
 {
     this.WatermarkImagePhysicalPath = watermarkImagePhysicalPath;
     base.AnchorLocation             = anchorLocation;
     base.Opacity = opacity;
 }
Ejemplo n.º 38
0
 public ImageWatermarkFilter(string watermarkImagePhysicalPath, AnchorLocation anchorLocation, float opacity)
 {
     this.WatermarkImagePhysicalPath = watermarkImagePhysicalPath;
     base.AnchorLocation = anchorLocation;
     base.Opacity = opacity;
 }
Ejemplo n.º 39
0
 public ImageWatermarkFilter(Image watermarkImage, AnchorLocation anchorLocation)
     : this(watermarkImage, anchorLocation, 0.6f)
 {
 }
Ejemplo n.º 40
0
 public ImageWatermarkFilter(string watermarkImagePhysicalPath, AnchorLocation anchorLocation)
     : this(watermarkImagePhysicalPath, anchorLocation, 0.6f)
 {
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageWatermarkFilter"/> class.
 /// </summary>
 /// <param name="watermarkImagePath">The watermark image path.</param>
 /// <param name="anchorLocation">The anchor location.</param>
 public ImageWatermarkFilter(string watermarkImagePath, AnchorLocation anchorLocation = AnchorLocation.BottomRight)
     : this(Image.FromFile(watermarkImagePath), anchorLocation)
 {
 }
Ejemplo n.º 42
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="text">水印文字</param>
 /// <param name="anchorLocation">水印在图像上的停靠位置 </param>
 /// <param name="opacity">不透明度</param>
 public TextWatermarkFilter(string text, AnchorLocation anchorLocation, float opacity)
 {
     this.Text           = text;
     base.AnchorLocation = anchorLocation;
     base.Opacity        = opacity;
 }
Ejemplo n.º 43
0
 public TextWatermarkFilter(string text, AnchorLocation anchorLocation, float opacity)
 {
     this.Text = text;
     base.AnchorLocation = anchorLocation;
     base.Opacity = opacity;
 }
Ejemplo n.º 44
0
        private Point GetDrawStartPoint(AnchorLocation location)
        {
            Point startPoint = new Point(0.0, 0.0);

            switch (AnchorLocation)
            {
                case AnchorLocation.None:
                case AnchorLocation.RightBottom:
                case AnchorLocation.BottomRight:
                    break;
                case AnchorLocation.TopLeft:
                    startPoint.X = AnchorPoint.X < 0 ? startPoint.X + Math.Abs(AnchorPoint.X) : startPoint.X;
                    startPoint.Y = startPoint.Y + Math.Abs(AnchorPoint.Y);
                    break;
                case AnchorLocation.TopRight:
                    startPoint.Y = startPoint.Y + Math.Abs(AnchorPoint.Y);
                    break;
                case AnchorLocation.LeftTop:
                    startPoint.X = startPoint.X + Math.Abs(AnchorPoint.X);
                    startPoint.Y = AnchorPoint.Y < 0 ? startPoint.Y + Math.Abs(AnchorPoint.Y) : startPoint.Y;
                    break;
                case AnchorLocation.LeftBottom:
                    startPoint.X = startPoint.X + Math.Abs(AnchorPoint.X);
                    break;
                case AnchorLocation.RightTop:
                    startPoint.Y = AnchorPoint.Y < 0 ? startPoint.Y + Math.Abs(AnchorPoint.Y) : startPoint.Y;
                    break;
                case AnchorLocation.BottomLeft:
                    startPoint.X = AnchorPoint.X < 0 ? startPoint.X + Math.Abs(AnchorPoint.X) : startPoint.X;
                    break;
            }

            return startPoint;
        }
Ejemplo n.º 45
0
		/// <summary>
		/// Anchors a control at the given location.
		/// </summary>
		public void AnchorControl(Renderable2D control, AnchorLocation location)
		{
			if (anchors[location].Control != null)
				throw new Exception("There's already something at this anchor.");

			anchors[location].Control = control;
		}
Ejemplo n.º 46
0
		/// <summary>
		/// Renders a triangle portion of a control.
		/// </summary>
		protected virtual void FillTriangle(Coord size, HitState hitState, AnchorLocation triDirection, AnchorLocation gradDirection)
		{
			var point = Context.Push();
			
			// Create the gradient
			Cairo.LinearGradient grad = GenerateGradient(point.Coord(), size / 2.0, gradDirection, 
			                                             GetColor(ColorType.BackgroundStart, hitState),
			                                             GetColor(ColorType.BackgroundStop, hitState));
			// draw the triangle
			Context.Cairo.Operator = Cairo.Operator.Source;
			Context.Cairo.Pattern = grad;
			switch (triDirection)
			{
			case AnchorLocation.NE:
				Context.Cairo.RelLineTo(size.X, 0);
				Context.Cairo.RelLineTo(0, size.Y);
				break;
			case AnchorLocation.NW:
				Context.Cairo.RelLineTo(size.X, 0);
				Context.Cairo.RelLineTo(-size.X, size.Y);
				break;
			case AnchorLocation.SE:
				Context.Cairo.MoveTo(size.X, 0);
				Context.Cairo.RelLineTo(0, size.Y);
				Context.Cairo.RelLineTo(-size.X, 0);
				break;
			case AnchorLocation.SW:
				Context.Cairo.RelLineTo(0, size.Y);
				Context.Cairo.RelLineTo(size.X, 0);
				break;
			case AnchorLocation.N:
				Context.Cairo.RelMoveTo(0, size.Y);
				Context.Cairo.RelLineTo(size.X, 0);
				Context.Cairo.RelLineTo(-size.X/2.0, size.Y);
				break;
			case AnchorLocation.E:
				Context.Cairo.RelLineTo(0, size.Y);
				Context.Cairo.RelLineTo(size.X, -size.Y/2.0);
				break;
			case AnchorLocation.S:
				Context.Cairo.RelLineTo(size.X, 0);
				Context.Cairo.RelLineTo(-size.X/2.0, size.Y);
				break;
			case AnchorLocation.W:
				Context.Cairo.RelMoveTo(size.X, 0);
				Context.Cairo.RelLineTo(0, size.Y);
				Context.Cairo.RelLineTo(-size.X, -size.Y/2.0);
				break;
			default:
				throw new Exception(triDirection.ToString() + " is currently not a valid triangle location");
			}
			Context.Cairo.Fill();
			
			Context.Pop();
		}
Ejemplo n.º 47
0
        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);
        }
Ejemplo n.º 48
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="text">水印文字</param>
 /// <param name="anchorLocation">水印在图像上的停靠位置 </param>
 public TextWatermarkFilter(string text, AnchorLocation anchorLocation)
     : this(text, anchorLocation, 0.6F)
 {
 }
Ejemplo n.º 49
0
		/// <summary>
		/// Creates a gradient for the given position, size, and anchor location.
		/// </summary>
		protected Cairo.LinearGradient GenerateGradient(Coord point, Coord size, AnchorLocation location, 
		                                                Color startColor, Color stopColor)
		{
			Cairo.LinearGradient grad = null;
			var x = point.X;
			var y = point.Y;
			var r = (size.X + size.Y) / 2.0;
			switch (location)
			{
			case AnchorLocation.E:
				grad = new Cairo.LinearGradient(x + size.X, y, x, y);
				break;
			case AnchorLocation.NE:
				grad = new Cairo.LinearGradient(x + r, y, x, y + r);
				break;
			case AnchorLocation.N:
				grad = new Cairo.LinearGradient(x, y, x, y + size.Y);
				break;
			case AnchorLocation.NW:
				grad = new Cairo.LinearGradient(x, y, x + r, y + r);
				break;
			case AnchorLocation.W:
				grad = new Cairo.LinearGradient(x, y, x + size.X, y);
				break;
			case AnchorLocation.SW:
				grad = new Cairo.LinearGradient(x, y + r, x + r, y);
				break;
			case AnchorLocation.S:
				grad = new Cairo.LinearGradient(x, y + size.Y, x, y);
				break;
			case AnchorLocation.SE:
				grad = new Cairo.LinearGradient(x + r, y + r, x, y);
				break;
			}
			
			// assign the colors
			if (startColor == null)
				startColor = defaultBackgroundColor;
			grad.AddColorStop(0, startColor.ToCairo());
			if (stopColor == null)
				stopColor = defaultBackgroundColor;
			grad.AddColorStop(1, stopColor.ToCairo());
			
			return grad;
		}
Ejemplo n.º 50
0
		/// <summary>
		/// Renders a rectangular background portion of a control.
		/// </summary>
		protected virtual void FillRectangle(Coord relPos, Coord size, Corner rounded, FillType fillType, HitState hitState, AnchorLocation location)
		{
			var point = Context.Push();
			var coord = new Coord(point.X + relPos.X, point.Y + relPos.Y);
			
			switch (fillType)
			{
			case FillType.Background:
				Context.Cairo.Pattern = GenerateGradient(coord, size, location, 
                                             GetColor(ColorType.BackgroundStart, hitState),
                                             GetColor(ColorType.BackgroundStop, hitState));
				break;
			case FillType.Editable:
				Context.Cairo.Pattern = GenerateGradient(coord, size, location, 
                                             GetColor(ColorType.EditableStart, hitState),
                                             GetColor(ColorType.EditableStop, hitState));
				break;
			case FillType.Highlight:
				Context.Cairo.Pattern = GenerateGradient(coord, size, location, 
                                             GetColor(ColorType.HighlightStart, hitState),
                                             GetColor(ColorType.HighlightStop, hitState));
				break;
			case FillType.Selection:
				Context.Cairo.Color = SelectionColor.ToCairo();
				break;
			}
			
			// draw the rectangle
			Context.Cairo.Operator = Cairo.Operator.Source;
			RectanglePath(coord.Round + 1, size.Floor - 2, rounded);
			Context.Cairo.Fill();
			
			Context.Pop();
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="ImageWatermarkFilter"/> class.
		/// </summary>
		/// <param name="watermarkImage">The watermark image.</param>
		/// <param name="anchorLocation">The anchor location.</param>
		public ImageWatermarkFilter(Image watermarkImage, AnchorLocation anchorLocation = AnchorLocation.BottomRight)
		{
			this.WatermarkImage = watermarkImage;
			this.AnchorLocation = anchorLocation;
		}
Ejemplo n.º 52
0
 public TextWatermarkFilter(string text, AnchorLocation anchorLocation)
     : this(text, anchorLocation, 0.6f)
 {
 }