【问题标题】:Select an image from rectangle using writeablebitmap使用 writeablebitmap 从矩形中选择图像
【发布时间】:2013-10-07 15:19:19
【问题描述】:

我在 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;
   }

每当执行此代码时,都会捕捉整个图像,而不是矩形选择的部分。谁能指导我在这里做错了什么。

【问题讨论】:

    标签: c# silverlight xaml writeablebitmap writeablebitmapex


    【解决方案1】:

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

    【讨论】:

    • 我建议使用笔和纸来思考您遇到的问题并使用一些示例值。想想你的问题。
    猜你喜欢
    • 1970-01-01
    • 2020-01-09
    • 2017-12-18
    • 2015-06-10
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2015-08-07
    相关资源
    最近更新 更多