Exemple #1
0
        //Render:When your image has changed, call it
        public void Render(ICanvasResourceCreator creator, float scaleX, float scaleY, ICanvasImage image)
        {
            //Scale :zoom up
            ScaleEffect effect = new ScaleEffect
            {
                Source            = image,
                Scale             = new Vector2(1 / scaleX, 1 / scaleY),
                InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
            };
            //Crop:So that it does not exceed the canvas boundary
            Rect       rect    = effect.GetBounds(creator);
            CropEffect effect2 = new CropEffect
            {
                Source          = effect,
                SourceRectangle = new Rect(2, 2, rect.Width - 4, rect.Height - 4),
            };


            //DottedLine
            this.OutPut = new LuminanceToAlphaEffect //Alpha
            {
                Source = new EdgeDetectionEffect     //Edge
                {
                    Amount = 1,
                    Source = effect2
                },
            };
        }
Exemple #2
0
        // crop
        public SoftwareBitmap Crop(SoftwareBitmap softwareBitmap, Rect bounds)
        {
            if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8)
            {
                softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8);
            }

            var resourceCreator = CanvasDevice.GetSharedDevice();

            using (var canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(resourceCreator, softwareBitmap))
                using (var canvasRenderTarget = new CanvasRenderTarget(resourceCreator, (float)bounds.Width, (float)bounds.Width, canvasBitmap.Dpi))
                    using (var drawingSession = canvasRenderTarget.CreateDrawingSession())
                        using (var cropEffect = new CropEffect())
                            using (var atlasEffect = new AtlasEffect())
                            {
                                drawingSession.Clear(Colors.White);

                                cropEffect.SourceRectangle = bounds;
                                cropEffect.Source          = canvasBitmap;

                                atlasEffect.SourceRectangle = bounds;
                                atlasEffect.Source          = cropEffect;

                                drawingSession.DrawImage(atlasEffect);
                                drawingSession.Flush();

                                return(SoftwareBitmap.CreateCopyFromBuffer(canvasRenderTarget.GetPixelBytes().AsBuffer(), BitmapPixelFormat.Bgra8, (int)bounds.Width, (int)bounds.Width, BitmapAlphaMode.Premultiplied));
                            }
        }
Exemple #3
0
        public async Task <IEnumerable <Tuple <Point, DavinciImage> > > ToTilesAsync(double tileWidth, double tileHight)
        {
            var listResults = new List <Tuple <Point, DavinciImage> >();

            Size size;

            size = await GetSize(_source);

            var numberOfHorizontalTiles = (int)size.Width / tileWidth;
            var numberOfVerticalTiles   = (int)size.Height / tileHight;

            for (var y = 0; y < numberOfVerticalTiles; y++)
            {
                for (var x = 0; x < numberOfHorizontalTiles; x++)

                {
                    try
                    {
                        var cropEffect = new CropEffect(_source)
                        {
                            CropArea = new Rect(x * tileWidth, y * tileHight, tileWidth, tileHight)
                        };
                        listResults.Add(new Tuple <Point, DavinciImage>(new Point(x, y), new DavinciImage(cropEffect)));
                    }
                    catch (Exception e)
                    {
                        throw;
                    }
                }
            }

            return(listResults);
        }
Exemple #4
0
        public static SoftwareBitmap CropAndResize(this SoftwareBitmap softwareBitmap, Rect bounds, float newWidth, float newHeight)
        {
            var resourceCreator = CanvasDevice.GetSharedDevice();

            using (var canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(resourceCreator, softwareBitmap))
                using (var canvasRenderTarget = new CanvasRenderTarget(resourceCreator, newWidth, newHeight, canvasBitmap.Dpi))
                    using (var drawingSession = canvasRenderTarget.CreateDrawingSession())
                        using (var scaleEffect = new ScaleEffect())
                            using (var cropEffect = new CropEffect())
                                using (var atlasEffect = new AtlasEffect())
                                {
                                    drawingSession.Clear(Colors.White);

                                    cropEffect.SourceRectangle = bounds;
                                    cropEffect.Source          = canvasBitmap;

                                    atlasEffect.SourceRectangle = bounds;
                                    atlasEffect.Source          = cropEffect;

                                    scaleEffect.Source = atlasEffect;
                                    scaleEffect.Scale  = new System.Numerics.Vector2(newWidth / (float)bounds.Width, newHeight / (float)bounds.Height);
                                    drawingSession.DrawImage(scaleEffect);
                                    drawingSession.Flush();

                                    return(SoftwareBitmap.CreateCopyFromBuffer(canvasRenderTarget.GetPixelBytes().AsBuffer(), BitmapPixelFormat.Bgra8, (int)newWidth, (int)newHeight, BitmapAlphaMode.Premultiplied));
                                }
        }
        public CropEffectProcessor()
        {
            Name         = "Crop Effect";
            m_cropEffect = new CropEffect();

            m_propertyDescriptions = new Dictionary <string, PropertyDescription>();
            m_propertyDescriptions.Add("Left", new PropertyDescription(0, 1.0, 0));
            m_propertyDescriptions.Add("Top", new PropertyDescription(0, 1.0, 0));
            m_propertyDescriptions.Add("Right", new PropertyDescription(0, 1.0, 0.5));
            m_propertyDescriptions.Add("Bottom", new PropertyDescription(0, 1.0, 0.5));

            SetupEffectCategory(m_cropEffect);

            AddEditors();
        }
        public CropEffectProcessor()
        {
            Name = "Crop Effect";
            m_cropEffect = new CropEffect();

            m_propertyDescriptions = new Dictionary<string, PropertyDescription>();
            m_propertyDescriptions.Add("Left", new PropertyDescription(0,1.0, 0));
            m_propertyDescriptions.Add("Top", new PropertyDescription(0, 1.0, 0));
            m_propertyDescriptions.Add("Right", new PropertyDescription(0, 1.0, 0.5));
            m_propertyDescriptions.Add("Bottom", new PropertyDescription(0, 1.0, 0.5));

            SetupEffectCategory(m_cropEffect);

            AddEditors();         
                
        }
Exemple #7
0
        private ICanvasImage CreateShadow()
        {
            var renderTarget = new CanvasRenderTarget(canvas, 360, 150);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                ds.Clear(Color.FromArgb(0, 0, 0, 0));

                ds.DrawText("This text is drawn onto a rendertarget", 10, 10, Colors.White);
                ds.DrawText("with a different color per line,", 10, 40, Colors.Red);
                ds.DrawText("after which a drop shadow is", 10, 70, Colors.Green);
                ds.DrawText("generated using image effects.", 10, 100, Colors.Blue);
            }

            var shadowEffect = new Transform2DEffect
            {
                Source = new ShadowEffect
                {
                    Source     = renderTarget,
                    BlurAmount = 2
                },
                TransformMatrix = Matrix3x2.CreateTranslation(3, 3)
            };

            var whiteBackground = new CropEffect
            {
                Source = new ColorSourceEffect {
                    Color = Colors.White
                },
                SourceRectangle = renderTarget.Bounds
            };

            var compositeEffect = new CompositeEffect
            {
                Sources = { whiteBackground, shadowEffect, renderTarget }
            };

            animationFunction = elapsedTime => { };

            currentEffectSize = renderTarget.Size.ToVector2();

            return(compositeEffect);
        }
Exemple #8
0
        public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
        {
            canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device, CanvasDebugLevel.None);
            numColumns   = (uint)(encodingProperties.Width / pixelsPerTile);
            numRows      = (uint)(encodingProperties.Height / pixelsPerTile);
            transforms   = new Transform2DEffect[numColumns, numRows];
            crops        = new CropEffect[numColumns, numRows];

            for (uint i = 0; i < numColumns; i++)
            {
                for (uint j = 0; j < numRows; j++)
                {
                    crops[i, j] = new CropEffect();
                    crops[i, j].SourceRectangle = new Rect(i * pixelsPerTile, j * pixelsPerTile, pixelsPerTile, pixelsPerTile);
                    transforms[i, j]            = new Transform2DEffect();
                    transforms[i, j].Source     = crops[i, j];
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Helper metohd that crop a SoftwareBitmap given a new bounding box
 /// </summary>
 private SoftwareBitmap CropSoftwareBitmap(SoftwareBitmap softwareBitmap, float x, float y, float width, float height)
 {
     using (var resourceCreator = CanvasDevice.GetSharedDevice())
         using (var canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(resourceCreator, softwareBitmap))
             using (var canvasRenderTarget = new CanvasRenderTarget(resourceCreator, width, height, canvasBitmap.Dpi))
                 using (var drawingSession = canvasRenderTarget.CreateDrawingSession())
                     using (var cropEffect = new CropEffect())
                     {
                         cropEffect.Source = canvasBitmap;
                         drawingSession.DrawImage(
                             cropEffect,
                             new Rect(0.0, 0.0, width, height),
                             new Rect(x, y, width, height),
                             (float)1.0,
                             CanvasImageInterpolation.HighQualityCubic);
                         drawingSession.Flush();
                         return(SoftwareBitmap.CreateCopyFromBuffer(canvasRenderTarget.GetPixelBytes().AsBuffer(), BitmapPixelFormat.Rgba8, (int)width, (int)height, BitmapAlphaMode.Premultiplied));
                     }
 }
        public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
        {
            _canvasDevice = device != null?CanvasDevice.CreateFromDirect3D11Device(device) : CanvasDevice.GetSharedDevice();

            _numColumns = (uint)(encodingProperties.Width / PixelsPerTile);
            _numRows    = (uint)(encodingProperties.Height / PixelsPerTile);
            _transforms = new Transform2DEffect[_numColumns, _numRows];
            _crops      = new CropEffect[_numColumns, _numRows];

            for (uint i = 0; i < _numColumns; i++)
            {
                for (uint j = 0; j < _numRows; j++)
                {
                    _crops[i, j] = new CropEffect();
                    _crops[i, j].SourceRectangle = new Rect(i * PixelsPerTile, j * PixelsPerTile, PixelsPerTile, PixelsPerTile);
                    _transforms[i, j]            = new Transform2DEffect();
                    _transforms[i, j].Source     = _crops[i, j];
                }
            }
        }
Exemple #11
0
        public ICanvasImage Apply(ICanvasImage image)
        {
            if (IsEnabled)
            {
                var  originalImage = image;
                Rect?bounds        = null;

                // Apply all our effects in turn.
                foreach (var effect in Effects)
                {
                    image = effect.Apply(image, ref bounds);
                }

                // Mask so these effects only alter a specific region of the image?
                if (regionMask != null)
                {
                    var selectedRegion = new CompositeEffect
                    {
                        Sources = { image, GetRegionMask() },
                        Mode    = CanvasComposite.DestinationIn
                    };

                    image = new CompositeEffect
                    {
                        Sources = { originalImage, selectedRegion }
                    };

                    if (bounds.HasValue)
                    {
                        image = new CropEffect
                        {
                            Source          = image,
                            SourceRectangle = bounds.Value
                        };
                    }
                }
            }

            return(image);
        }
Exemple #12
0
        private ICanvasImage CreateCrop()
        {
            var cropEffect = new CropEffect
            {
                Source = bitmapTiger
            };

            // Animation alters what area of the bitmap is selected.
            animationFunction = elapsedTime =>
            {
                var w = 50 + (float)Math.Sin(elapsedTime / 2) * 40;
                var h = 50 + (float)Math.Sin(elapsedTime / 3) * 40;

                var range = bitmapTiger.Size.ToVector2() - new Vector2(w, h);

                var x = (Math.Sin(elapsedTime * 4) + 1) / 2 * range.X;
                var y = (Math.Sin(elapsedTime * 5) + 1) / 2 * range.Y;

                cropEffect.SourceRectangle = new Rect(x, y, w, h);
            };

            return(cropEffect);
        }
Exemple #13
0
        private IImageProvider Crop(BitmapImageSource overlayBitmapImageSource, ImageProviderInfo originalOverlayImageProviderInfo, int backgroundWidth, int backgroundHeight)
        {
            IImageProvider imageProvider;

            int overlayWidth  = (int)overlayBitmapImageSource.Bitmap.Dimensions.Width;
            int overlayHeight = (int)overlayBitmapImageSource.Bitmap.Dimensions.Height;

            if (HorizontalAlignment != HorizontalAlignment.None)
            {
                int cropLeft   = 0;
                int cropTop    = 0;
                int cropWidth  = Math.Min(overlayWidth, (int)originalOverlayImageProviderInfo.ImageSize.Width);
                int cropHeight = Math.Min(overlayHeight, (int)originalOverlayImageProviderInfo.ImageSize.Height);

                if ((HorizontalAlignment == HorizontalAlignment.Center) &&
                    (overlayWidth < (int)originalOverlayImageProviderInfo.ImageSize.Width))
                {
                    cropLeft   = Math.Abs(overlayWidth / 2 - backgroundWidth / 2);
                    cropWidth -= cropLeft * 2;
                }

                if ((VerticalAlignment == HorizontalAlignment.Center) &&
                    (overlayHeight < (int)originalOverlayImageProviderInfo.ImageSize.Height))
                {
                    cropTop     = Math.Abs(overlayHeight / 2 - backgroundHeight / 2);
                    cropHeight -= cropTop * 2;
                }

                imageProvider = new CropEffect(new Rect(cropLeft, cropTop, cropWidth, cropHeight));
            }
            else
            {
                imageProvider = overlayBitmapImageSource;
            }

            return(imageProvider);
        }
Exemple #14
0
        //方法:设置(写到创建资源事件里)
        public void Set(ICanvasResourceCreator rc, float sx, float sy, ICanvasImage ci)
        {
            //放大
            ScaleEffect se = new ScaleEffect
            {
                Source            = ci,
                Scale             = new Vector2(1 / sx, 1 / sy),
                InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
            };

            //剪裁四周的边线
            var        rect = se.GetBounds(rc);
            CropEffect sce  = new CropEffect
            {
                Source          = se,
                SourceRectangle = new Rect(2, 2, rect.Width - 4, rect.Height - 4),
            };

            //恢复正常大小
            CanvasCommandList ccl = new CanvasCommandList(rc);

            using (var ds = ccl.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);
                ds.DrawImage(sce);
            }

            //变成线框
            Image = new LuminanceToAlphaEffect   //亮度转不透明度
            {
                Source = new EdgeDetectionEffect //边缘检测
                {
                    Amount = 1,
                    Source = ccl
                },
            };
        }
        private ICanvasImage CreateShadow()
        {
            var renderTarget = new CanvasRenderTarget(canvas, 360, 150);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                ds.Clear(Color.FromArgb(0, 0, 0, 0));

                ds.DrawText("This text is drawn onto a rendertarget", 10, 10, Colors.White);
                ds.DrawText("with a different color per line,", 10, 40, Colors.Red);
                ds.DrawText("after which a drop shadow is", 10, 70, Colors.Green);
                ds.DrawText("generated using image effects.", 10, 100, Colors.Blue);
            }

            var shadowEffect = new Transform2DEffect
            {
                Source = new ShadowEffect
                {
                    Source = renderTarget,
                    BlurAmount = 2
                },
                TransformMatrix = Matrix3x2.CreateTranslation(3, 3)
            };

            var whiteBackground = new CropEffect
            {
                Source = new ColorSourceEffect { Color = Colors.White },
                SourceRectangle = renderTarget.Bounds
            };

            var compositeEffect = new CompositeEffect
            {
                Sources = { whiteBackground, shadowEffect, renderTarget }
            };

            animationFunction = elapsedTime => { };

            currentEffectSize = renderTarget.Size.ToVector2();

            return compositeEffect;
        }
        private ICanvasImage CreateLuminanceToAlpha()
        {
            var contrastAdjustedTiger = new LinearTransferEffect
            {
                Source = bitmapTiger,

                RedOffset = -3,
                GreenOffset = -3,
                BlueOffset = -3,
            };

            var tigerAlpha = new LuminanceToAlphaEffect
            {
                Source = contrastAdjustedTiger
            };

            var tigerAlphaWithWhiteRgb = new LinearTransferEffect
            {
                Source = tigerAlpha,
                RedOffset = 1,
                GreenOffset = 1,
                BlueOffset = 1,
                RedSlope = 0,
                GreenSlope = 0,
                BlueSlope = 0,
            };

            var recombinedRgbAndAlpha = new ArithmeticCompositeEffect
            {
                Source1 = tigerAlphaWithWhiteRgb,
                Source2 = bitmapTiger,
            };

            var movedTiger = new Transform2DEffect
            {
                Source = recombinedRgbAndAlpha
            };

            const float turbulenceSize = 128;

            var backgroundImage = new CropEffect
            {
                Source = new TileEffect
                {
                    Source = new TurbulenceEffect
                    {
                        Octaves = 8,
                        Size = new Vector2(turbulenceSize),
                        Tileable = true
                    },
                    SourceRectangle= new Rect(0, 0, turbulenceSize, turbulenceSize)
                },
                SourceRectangle = new Rect((bitmapTiger.Size.ToVector2() * -0.5f).ToPoint(),
                                           (bitmapTiger.Size.ToVector2() * 1.5f).ToPoint())
            };

            var tigerOnBackground = new BlendEffect
            {
                Foreground = movedTiger,
                Background = backgroundImage
            };

            // Animation moves the alpha bitmap around, and alters color transfer settings to change how solid it is.
            animationFunction = elapsedTime =>
            {
                contrastAdjustedTiger.RedSlope =
                contrastAdjustedTiger.GreenSlope =
                contrastAdjustedTiger.BlueSlope = ((float)Math.Sin(elapsedTime * 0.9) + 2) * 3;

                var dx = (float)Math.Cos(elapsedTime) * 50;
                var dy = (float)Math.Sin(elapsedTime) * 50;

                movedTiger.TransformMatrix = Matrix3x2.CreateTranslation(dx, dy);
            };

            return tigerOnBackground;
        }
        private ICanvasImage CreateCrop()
        {
            var cropEffect = new CropEffect
            {
                Source = bitmapTiger
            };

            // Animation alters what area of the bitmap is selected.
            animationFunction = elapsedTime =>
            {
                var w = 50 + (float)Math.Sin(elapsedTime / 2) * 40;
                var h = 50 + (float)Math.Sin(elapsedTime / 3) * 40;

                var range = bitmapTiger.Size.ToVector2() - new Vector2(w, h);

                var x = (Math.Sin(elapsedTime * 4) + 1) / 2 * range.X;
                var y = (Math.Sin(elapsedTime * 5) + 1) / 2 * range.Y;

                cropEffect.SourceRectangle = new Rect(x, y, w, h);
            };

            return cropEffect;
        }
Exemple #18
0
        public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
        {
            canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device);
            numColumns = (uint)(encodingProperties.Width / pixelsPerTile);
            numRows = (uint)(encodingProperties.Height / pixelsPerTile);
            transforms = new Transform2DEffect[numColumns, numRows];
            crops = new CropEffect[numColumns, numRows];

            for (uint i = 0; i < numColumns; i++)
            {
                for (uint j = 0; j < numRows; j++)
                {
                    crops[i, j] = new CropEffect();
                    crops[i, j].SourceRectangle = new Rect(i * pixelsPerTile, j * pixelsPerTile, pixelsPerTile, pixelsPerTile);
                    transforms[i, j] = new Transform2DEffect();
                    transforms[i, j].Source = crops[i, j];
                }
            }
        }
Exemple #19
0
        private ICanvasImage CreateLuminanceToAlpha()
        {
            var contrastAdjustedTiger = new LinearTransferEffect
            {
                Source = bitmapTiger,

                RedOffset   = -3,
                GreenOffset = -3,
                BlueOffset  = -3,
            };

            var tigerAlpha = new LuminanceToAlphaEffect
            {
                Source = contrastAdjustedTiger
            };

            var tigerAlphaWithWhiteRgb = new LinearTransferEffect
            {
                Source      = tigerAlpha,
                RedOffset   = 1,
                GreenOffset = 1,
                BlueOffset  = 1,
                RedSlope    = 0,
                GreenSlope  = 0,
                BlueSlope   = 0,
            };

            var recombinedRgbAndAlpha = new ArithmeticCompositeEffect
            {
                Source1 = tigerAlphaWithWhiteRgb,
                Source2 = bitmapTiger,
            };

            var movedTiger = new Transform2DEffect
            {
                Source = recombinedRgbAndAlpha
            };

            const float turbulenceSize = 128;

            var backgroundImage = new CropEffect
            {
                Source = new TileEffect
                {
                    Source = new TurbulenceEffect
                    {
                        Octaves  = 8,
                        Size     = new Vector2(turbulenceSize),
                        Tileable = true
                    },
                    SourceRectangle = new Rect(0, 0, turbulenceSize, turbulenceSize)
                },
                SourceRectangle = new Rect((bitmapTiger.Size.ToVector2() * -0.5f).ToPoint(),
                                           (bitmapTiger.Size.ToVector2() * 1.5f).ToPoint())
            };

            var tigerOnBackground = new BlendEffect
            {
                Foreground = movedTiger,
                Background = backgroundImage
            };

            // Animation moves the alpha bitmap around, and alters color transfer settings to change how solid it is.
            animationFunction = elapsedTime =>
            {
                contrastAdjustedTiger.RedSlope          =
                    contrastAdjustedTiger.GreenSlope    =
                        contrastAdjustedTiger.BlueSlope = ((float)Math.Sin(elapsedTime * 0.9) + 2) * 3;

                var dx = (float)Math.Cos(elapsedTime) * 50;
                var dy = (float)Math.Sin(elapsedTime) * 50;

                movedTiger.TransformMatrix = Matrix3x2.CreateTranslation(dx, dy);
            };

            return(tigerOnBackground);
        }
Exemple #20
0
        public ICanvasImage Apply(ICanvasImage image)
        {
            if (IsEnabled)
            {
                var originalImage = image;
                Rect? bounds = null;

                // Apply all our effects in turn.
                foreach (var effect in Effects)
                {
                    image = effect.Apply(image, ref bounds);
                }

                // Mask so these effects only alter a specific region of the image?
                if (regionMask != null)
                {
                    var selectedRegion = new CompositeEffect
                    {
                        Sources = { image, GetRegionMask() },
                        Mode = CanvasComposite.DestinationIn
                    };

                    image = new CompositeEffect
                    {
                        Sources = { originalImage, selectedRegion }
                    };

                    if (bounds.HasValue)
                    {
                        image = new CropEffect
                        {
                            Source = image,
                            SourceRectangle = bounds.Value
                        };
                    }
                }
            }

            return image;
        }
Exemple #21
0
        private void DrawBackImage(CanvasDrawingSession graphics, double scale)
        {
            if (editimage != null)
            {
                Rect des = GetImageDrawingRect();
                des.X      *= scale;
                des.Y      *= scale;
                des.Width  *= scale;
                des.Height *= scale;
                // 滤镜特效

                //亮度
                ICanvasImage image = GetBrightnessEffect(editimage);
                //对比度
                image = GetContrastEffect(image);
                //饱和度
                image = GetSaturationEffect(image);
                //锐化
                image = GetSharpenEffect(image);
                //模糊
                image = GetBlurEffect(image);

                ////应用滤镜模板
                image = ApplyFilterTemplate(image);

                var width_scale  = editimage.Bounds.Width / des.Width;
                var height_scale = editimage.Bounds.Height / des.Height;
                if (cutok)
                {
                    left          = (float)cutmanage.cutPointX;
                    top           = (float)cutmanage.cutPointY;
                    descut.X      = (cutmanage.cutPointX - des.X) * width_scale;
                    descut.Y      = (cutmanage.cutPointY - des.Y) * height_scale;
                    descut.Width  = cutmanage.cutWidth * width_scale;
                    descut.Height = cutmanage.cutHeight * height_scale;
                    cutok         = false;
                    cutmanage     = null;
                }
                //des.Width = 100;
                //Vector2 vec = new Vector2();


                if (iscuted)
                {
                    //graphics.DrawImage(_image, left,top,descut);

                    if (cuted)
                    {
                        //graphics.DrawImage(image, des, descut);
                        //image = new AtlasEffect { Source = image, SourceRectangle = descut };
                        image = new CropEffect {
                            Source = image, SourceRectangle = descut
                        };
                    }
                    else
                    {
                        //graphics.DrawImage(image, des, descut);
                        //image = new AtlasEffect { Source = image, SourceRectangle = descut };
                        image = new CropEffect {
                            Source = image, SourceRectangle = descut
                        };
                        cuted = true;
                    }
                }
                //else
                //{
                //    graphics.DrawImage(image, des, editimage.Bounds);
                //}
                graphics.DrawImage(image, des, editimage.Bounds);
                //if(cutok)
                //{
                //    image = new CropEffect { Source = image, SourceRectangle = new Rect(cutmanage.cutPointX, cutmanage.cutPointY, cutmanage.cutWidth, cutmanage.cutHeight) };
                //    //cutok = false;
                //    cutmanage = null;
                //}
                //graphics.DrawImage(image, des, editimage.Bounds);
            }
        }
        private IImageProvider Crop(BitmapImageSource overlayBitmapImageSource, ImageProviderInfo originalOverlayImageProviderInfo, int backgroundWidth, int backgroundHeight)
        {
            IImageProvider imageProvider;

            int overlayWidth = (int)overlayBitmapImageSource.Bitmap.Dimensions.Width;
            int overlayHeight = (int)overlayBitmapImageSource.Bitmap.Dimensions.Height;

            if (HorizontalAlignment != HorizontalAlignment.None)
            {
                int cropLeft = 0;
                int cropTop = 0;
                int cropWidth = Math.Min(overlayWidth, (int)originalOverlayImageProviderInfo.ImageSize.Width);
                int cropHeight = Math.Min(overlayHeight, (int)originalOverlayImageProviderInfo.ImageSize.Height);

                if ((HorizontalAlignment == HorizontalAlignment.Center) &&
                    (overlayWidth < (int)originalOverlayImageProviderInfo.ImageSize.Width))
                {
                    cropLeft = Math.Abs(overlayWidth / 2 - backgroundWidth / 2);
                    cropWidth -= cropLeft * 2;
                }

                if ((VerticalAlignment == HorizontalAlignment.Center) &&
                    (overlayHeight < (int)originalOverlayImageProviderInfo.ImageSize.Height))
                {
                    cropTop = Math.Abs(overlayHeight / 2 - backgroundHeight / 2);
                    cropHeight -= cropTop * 2;
                }

                imageProvider = new CropEffect(new Rect(cropLeft, cropTop, cropWidth, cropHeight));
            }
            else
            {
                imageProvider = overlayBitmapImageSource;
            }

            return imageProvider;
        }