コード例 #1
0
        //该方法用于在画布上绘制一个图形,两个点用于表示图像的填充区域,image是原始的图片,angle是角度,只有{0,90,180,270}三个角度可选

        /***
         * public void drawImage(Point leftTop, Point rightBottom, BitmapImage bitmapImage)
         * {
         *  double left = leftTop.X;
         *  double top = leftTop.Y;
         *  double width = Math.Abs(leftTop.X - rightBottom.X);
         *  double height = Math.Abs(leftTop.Y - rightBottom.Y);
         *
         *  double leftWithRatio = left * this.widthRatio;
         *  double topWithRatio = top * this.heightRatio;
         *  double widthWithRatio = width * this.widthRatio;
         *  double heightWithRatio = height * this.heightRatio;
         *
         *  Image shelfImage = new Image();
         *  //RotateTransform rotateTransform = new RotateTransform(angle);
         *
         *  //DropShadowBitmapEffect bitmapEffect = new DropShadowBitmapEffect();
         *  //Color myShadowColor = new Color();
         *  //myShadowColor.ScA = 1;
         *  //myShadowColor.ScB = 0;
         *  //myShadowColor.ScG = 0;
         *  //myShadowColor.ScR = 0;
         *  //bitmapEffect.Color = myShadowColor;
         *  //bitmapEffect.Direction = 320;
         *  //bitmapEffect.ShadowDepth = 10;
         *  //bitmapEffect.Softness = 0.1;
         *  //bitmapEffect.Opacity = 0.1;
         *  shelfImage.Source = bitmapImage;
         *  shelfImage.Stretch = Stretch.Uniform;
         *  //shelfImage.BitmapEffect = bitmapEffect;
         *  //shelfImage.RenderTransform = rotateTransform;
         *  //shelfImage.Width = widthWithRatio;shelfImage.Height = heightWithRatio;
         *  shelfImage.Width = heightWithRatio; shelfImage.Height = widthWithRatio;
         *
         *  Canvas.SetTop(shelfImage,topWithRatio);//adjust the postion
         *  Canvas.SetLeft(shelfImage, leftWithRatio);
         *  Canvas.SetZIndex(shelfImage, -10);
         *  this.currentCanvas.Children.Add(shelfImage);
         * }
         ***/
        public void drawImage(Point leftTop, Point rightBottom, BitmapImage bitmapImage,
                              Transform rotateTransform, BitmapEffect bitmapEffect)
        {
            double left            = leftTop.X;
            double top             = leftTop.Y;
            double width           = Math.Abs(leftTop.X - rightBottom.X);
            double height          = Math.Abs(leftTop.Y - rightBottom.Y);
            double leftWithRatio   = left * this.widthRatio;
            double topWithRatio    = top * this.heightRatio;
            double widthWithRatio  = width * this.widthRatio;
            double heightWithRatio = height * this.heightRatio;

            Image shelfImage = new Image();

            shelfImage.Source          = bitmapImage;
            shelfImage.Stretch         = Stretch.Fill;
            shelfImage.RenderTransform = rotateTransform;
            shelfImage.BitmapEffect    = bitmapEffect;
            shelfImage.Width           = widthWithRatio - 3;
            shelfImage.Height          = heightWithRatio;
            //shelfImage.Width = heightWithRatio; shelfImage.Height = widthWithRatio;

            Canvas.SetTop(shelfImage, topWithRatio);//adjust the postion
            Canvas.SetLeft(shelfImage, leftWithRatio);
            Canvas.SetZIndex(shelfImage, -10);
            this.currentCanvas.Children.Add(shelfImage);
        }
コード例 #2
0
ファイル: VerticalIndicator.cs プロジェクト: agamat/Ribbon-1
 public VerticalIndicator()
 {
     _effect = new OuterGlowBitmapEffect {
         GlowColor = Colors.White, GlowSize = 20, Opacity = 1
     };
     _effect.Freeze();
 }
コード例 #3
0
ファイル: RenderBuffer.cs プロジェクト: dotnet/wpf-test
        /// <summary>
        /// Apply a bitmap effect to this RenderBuffer within the area defined by the effect input.
        /// </summary>
        public void ApplyEffect(BitmapEffect effect, BitmapEffectInput input)
        {
            if (effect == null)
            {
                return;
            }

            //
            Rect bounds = ComputeAreaToApplyEffect(input);

            if (bounds.IsEmpty)
            {
                // NOTE: Don't confuse 'bounds' with BitmapEffectInput.AreaToApplyEffect!
                // An empty area in the Input means to use the entire RenderTarget, and bounds
                //  is the size of the RenderTarget we want to apply the effect to.
                // At this stage, 'Empty' means that there is nothing to apply an effect to.
                return;
            }

            if (effect is DropShadowBitmapEffect)
            {
                ApplyDropShadow(effect as DropShadowBitmapEffect, bounds);
            }
            else
            {
                throw new NotImplementedException("Haven't implemented the " + effect.GetType().Name + " effect yet");
            }
        }
コード例 #4
0
        //==========================================================================
        public BitmapEffect ToBitmapEffect()
        {
            if (Document.Options.IgnoreEffects)
            {
                return(null);
            }

            BitmapEffectGroup bitmap_effect_group = new BitmapEffectGroup();

            foreach (SvgFilterEffectBaseElement filter_effect in FilterEffects)
            {
                BitmapEffect bitmap_effect = filter_effect.ToBitmapEffect();
                if (bitmap_effect != null)
                {
                    bitmap_effect_group.Children.Add(bitmap_effect);
                }
            }

            if (bitmap_effect_group.Children.Count == 0)
            {
                return(null);
            }

            return(bitmap_effect_group);
        }
コード例 #5
0
 public BlockTimeDisplayLayerDraw()
 {
     _effect = new OuterGlowBitmapEffect {
         GlowColor = Colors.White, GlowSize = 20, Opacity = 1
     };
     _effect.Freeze();
 }
コード例 #6
0
 public override void PushEffect(
     BitmapEffect effect,
     BitmapEffectInput effectInput)
 {
     _drawingContext.PushEffect(
         effect,
         effectInput
         );
 }
コード例 #7
0
        public override void PushEffect(
            BitmapEffect effect,
            BitmapEffectInput effectInput)
        {
            // Ensure the type stack
            PushTypeStack(PushType.BitmapEffect);

            // This API has been deprecated, so any BitmapEffect is ignored.
        }
 public override void PushEffect(
     BitmapEffect effect,
     BitmapEffectInput effectInput)
 {
     if (!IsPushNoOp())
     {
         // This API has been deprecated, so any BitmapEffect is ignored.
         PushPointStack(_point);
     }
 }
コード例 #9
0
        //==========================================================================
        public virtual Drawing Draw()
        {
            Drawing drawing = GetBaseDrawing();

            if (drawing == null)
            {
                return(null);
            }

            BitmapEffect bitmap_effect = null;

            if (Filter != null)
            {
                if (Document.Elements.ContainsKey(Filter))
                {
                    SvgFilterElement filter_element = Document.Elements[Filter] as SvgFilterElement;
                    if (filter_element != null)
                    {
                        bitmap_effect = filter_element.ToBitmapEffect();
                    }
                }
            }

            Brush opacity_mask = null;

            if (Mask != null)
            {
                SvgMaskElement mask_element = Document.Elements[Mask] as SvgMaskElement;
                if (mask_element != null)
                {
                    opacity_mask = mask_element.GetOpacityMask();
                    if (opacity_mask != null)
                    {
                        if (Transform != null)
                        {
                            opacity_mask.Transform = Transform.ToTransform();
                        }
                    }
                }
            }

            if ((opacity_mask == null) && (bitmap_effect == null))
            {
                return(drawing);
            }


            DrawingGroup drawing_group = new DrawingGroup();

            drawing_group.BitmapEffect = bitmap_effect;
            drawing_group.OpacityMask  = opacity_mask;
            drawing_group.Children.Add(drawing);

            return(drawing_group);
        }
コード例 #10
0
ファイル: Xaml2Emf.cs プロジェクト: ru-petrovi4/Ssz.Utils
        private static DrawingGroup WalkVisual(Visual visual)
        {
            DrawingGroup      vd  = VisualTreeHelper.GetDrawing(visual);
            BitmapEffect      be  = VisualTreeHelper.GetBitmapEffect(visual);
            BitmapEffectInput bei = VisualTreeHelper.GetBitmapEffectInput(visual);
            Geometry          cg  = VisualTreeHelper.GetClip(visual);
            double            op  = VisualTreeHelper.GetOpacity(visual);
            Brush             om  = VisualTreeHelper.GetOpacityMask(visual);
            GuidelineSet?     gs  = GetGuidelines(visual);
            Transform?        tx  = GetTransform(visual);

            DrawingGroup?dg = null;

            if (be is null && cg is null && om is null && gs is null && tx is null && IsZero(op - 1))
            {
                dg = vd ?? new DrawingGroup();
            }
コード例 #11
0
        unsafe protected override SafeHandle CreateUnmanagedEffect()
        {
            const uint CLSCTX_INPROC_SERVER = 1;
            Guid       IID_IUnknown         = new Guid("00000000-0000-0000-C000-000000000046");
            Guid       guidEffectCLSID      = new Guid("84CF07CC-34C4-460f-B435-3184F5F2FF2A");
            SafeHandle wrapper = BitmapEffect.CreateBitmapEffectOuter();

            COMSafeHandle unmanagedEffect;
            uint          hresult = Ole32Methods.CoCreateInstance(
                ref guidEffectCLSID,
                wrapper.DangerousGetHandle(),
                CLSCTX_INPROC_SERVER,
                ref IID_IUnknown,
                out unmanagedEffect);

            InitializeBitmapEffect(wrapper, unmanagedEffect);
            if (0 == hresult)
            {
                return(wrapper);
            }
            throw new Exception("Cannot instantiate effect. HRESULT = " + hresult.ToString());
        }
コード例 #12
0
ファイル: DrawingContext.cs プロジェクト: dox0/DotNet471RS3
 public abstract void PushEffect(
     BitmapEffect effect,
     BitmapEffectInput effectInput);
コード例 #13
0
 protected override void UpdateUnmanagedPropertyState(SafeHandle unmanagedEffect)
 {
     BitmapEffect.SetValue(unmanagedEffect, "Red", this.Red);
     BitmapEffect.SetValue(unmanagedEffect, "Green", this.Green);
     BitmapEffect.SetValue(unmanagedEffect, "Blue", this.Blue);
 }
コード例 #14
0
ファイル: RenderBuffer.cs プロジェクト: dotnet/wpf-test
 /// <summary>
 /// Apply a bitmap effect to this RenderBuffer
 /// </summary>
 public void ApplyEffect(BitmapEffect effect)
 {
     ApplyEffect(effect, null);
 }
コード例 #15
0
 public override void PushEffect(
     BitmapEffect effect,
     BitmapEffectInput effectInput)
 {
     Debug.Assert(false);
 }
コード例 #16
0
        private static Drawing CreateDrawing(Visual visual, bool includeTransform)
        {
            DrawingGroup drawingGroup = new DrawingGroup();

            System.Windows.Media.Geometry clip = VisualTreeHelper.GetClip(visual);
            if (clip != null)
            {
                drawingGroup.ClipGeometry = clip;
            }
            if (includeTransform)
            {
                Transform transform = VisualTreeHelper.GetTransform(visual);
                Vector    offset    = VisualTreeHelper.GetOffset(visual);
                Matrix    matrix    = transform == null ? Matrix.Identity : transform.Value;
                matrix.Translate(offset.X, offset.Y);
                if (!matrix.IsIdentity)
                {
                    drawingGroup.Transform = (Transform) new MatrixTransform(matrix);
                }
            }
            double opacity = VisualTreeHelper.GetOpacity(visual);

            if (opacity != 1.0)
            {
                drawingGroup.Opacity = opacity;
            }
            Brush opacityMask = VisualTreeHelper.GetOpacityMask(visual);

            if (opacityMask != null)
            {
                drawingGroup.OpacityMask = opacityMask;
            }
            BitmapEffect bitmapEffect = VisualTreeHelper.GetBitmapEffect(visual);

            if (bitmapEffect != null)
            {
                drawingGroup.BitmapEffect = bitmapEffect;
            }
            BitmapEffectInput bitmapEffectInput = VisualTreeHelper.GetBitmapEffectInput(visual);

            if (bitmapEffectInput != null && (!bitmapEffectInput.AreaToApplyEffect.IsEmpty || bitmapEffectInput.Input != BitmapEffectInput.ContextInputSource))
            {
                drawingGroup.BitmapEffectInput = bitmapEffectInput;
            }
            Drawing drawing1;

            if (MakeDrawingBrushCommand.IsMediaElementInstance(visual))
            {
                Rect bounds = VisualTreeHelper.GetDrawing(visual).Bounds;
                drawing1 = (Drawing) new VideoDrawing()
                {
                    Rect = bounds
                };
            }
            else
            {
                drawing1 = (Drawing)VisualTreeHelper.GetDrawing(visual);
            }
            if (drawing1 != null)
            {
                drawingGroup.Children.Add(drawing1);
            }
            for (int childIndex = 0; childIndex < VisualTreeHelper.GetChildrenCount((DependencyObject)visual); ++childIndex)
            {
                Visual visual1 = VisualTreeHelper.GetChild((DependencyObject)visual, childIndex) as Visual;
                if (visual1 != null)
                {
                    Drawing drawing2 = MakeDrawingBrushCommand.CreateDrawing(visual1, true);
                    if (drawing2 != null)
                    {
                        drawingGroup.Children.Add(drawing2);
                    }
                }
            }
            if (drawingGroup.Children.Count == 0)
            {
                return((Drawing)null);
            }
            if (drawingGroup.Children.Count == 1 && drawingGroup.ClipGeometry == null && (drawingGroup.Transform == null || drawingGroup.Transform.Value.IsIdentity) && (drawingGroup.Opacity == 1.0 && drawingGroup.OpacityMask == null && drawingGroup.BitmapEffect == null))
            {
                return(drawingGroup.Children[0]);
            }
            return((Drawing)drawingGroup);
        }