Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用writeablebitmap从矩形中选择图像_C#_Silverlight_Xaml_Writeablebitmap_Writeablebitmapex - Fatal编程技术网

C# 使用writeablebitmap从矩形中选择图像

C# 使用writeablebitmap从矩形中选择图像,c#,silverlight,xaml,writeablebitmap,writeablebitmapex,C#,Silverlight,Xaml,Writeablebitmap,Writeablebitmapex,我已经在silverlight中编写了一个应用程序,我正在图像上放置一个矩形,希望选择矩形覆盖的图像部分,并在单击按钮时将其显示在图像控件上 我不善于处理比率和图像处理的事情,所以我无法得到正确的方式 代码如下所示,如果有人能给我建议一种解决方法,我将不胜感激 public void CaptureImage(object sender, RoutedEventArgs e) { BitmapImage bitmapImage = new BitmapImage();

我已经在silverlight中编写了一个应用程序,我正在图像上放置一个矩形,希望选择矩形覆盖的图像部分,并在单击按钮时将其显示在图像控件上

我不善于处理比率和图像处理的事情,所以我无法得到正确的方式

代码如下所示,如果有人能给我建议一种解决方法,我将不胜感激

public void CaptureImage(object sender, RoutedEventArgs e)
{
            BitmapImage bitmapImage = new BitmapImage();
            //// bitmapImage.CreateOptions = BitmapCreateOptions.None;
            bitmapImage = NewImage;

            ////calculate bounding box
            int originalWidth = bitmapImage.PixelWidth;
            int originalHeight = bitmapImage.PixelHeight;

            int newSmallWidth = (int)SquareBlue.Width;
            int newSmallHeight = (int)SquareBlue.Height;

            ////generate temporary control to render image
            Image temporaryImage = new Image { Source = bitmapImage, Width = newSmallWidth, Height = newSmallHeight };

            ////create writeablebitmap
            WriteableBitmap wb = new WriteableBitmap(newSmallWidth, newSmallHeight);

            TranslateTransform t = new TranslateTransform();
            t.X = -5;
            t.Y = -5;

            wb.Render(temporaryImage, t);

            wb.Invalidate();

            myImage.Source = wb;
   }

每当执行此代码时,都会捕捉整个图像,而不是矩形所选的部分。任何人都可以告诉我我做错了什么。

我建议您使用提供的裁剪方法。

我建议使用纸笔思考您的问题,并使用一些样本值。想想你的问题。