将所选图像裁剪为ID卡大小

时间:2018-04-09 14:19:15

标签: c# image crop

我现在有一个学校项目正在进行,问题是从mediafiledialog中选择图像并将它们裁剪为特定大小。

这就是我到目前为止所做的事情:

//Selecting images to crop
    private void individualCropedImagesOpenClick(object sender, RoutedEventArgs e)
    {
        // First clean up existing tracking
        StopTracking();

        var image_files = openMediaDialog(true);
        ImageReader reader = new ImageReader(image_files, fx, fy, cx, cy);

        processing_thread = new Thread(() => ProcessIndividualImages(reader));
        processing_thread.Start();

        String filename = @"C:\Fotos\";
        FileStream masterImage = new FileStream(filename + DateTime.Now.ToString("yyyyMMdd_hhmmss") +"CROPPED" + ".jpg", FileMode.Create);
        // Create an Image element.
        Image croppedImage = overlay_image;
        croppedImage.Width = 200;
        croppedImage.Margin = new Thickness(5);
        // Create a CroppedBitmap based off of a xaml defined resource.
        CroppedBitmap cb = new CroppedBitmap(
           (BitmapSource)this.Resources["masterImage"],
           new Int32Rect(30, 20, 105, 50));       //select region rect
        croppedImage.Source = cb;   //set image source to cropped
    }

我知道我犯了一些错误但却不知道是什么。我的目标是使用开源面部检测在人处于正确位置时拍照,然后将图像裁剪为ID大小。计算机已经拍摄了图片并且工作正常,但无法裁剪。

ERROR消息是'返回null'并且在行

CroppedBitmap cb = new CroppedBitmap(
               (BitmapSource)this.Resources["masterImage"], 
               new Int32Rect(30, 20, 105, 50))

希望这是可以理解的......

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

几乎忘了说,它已经完成,所以不再需要帮助了,谢谢!!