【问题标题】:Crop a given image using PhotoChooserTask使用 PhotoChooserTask 裁剪给定的图像
【发布时间】:2014-08-05 14:10:18
【问题描述】:

在我的 Windows Phone 应用中,用户可以使用PhotoChooserTask 选择照片,并通过指定photoChooserTask.PixelWidthphotoChooserTask.PixelHeight 将它们裁剪为所需的尺寸。

但是,用户也可以通过图像的编辑按钮(使用 Photos_Extra_Image_Editor 扩展名)访问我的应用。问题是这些图像可以有任意尺寸,所以我也想在这里使用 WP 的内置裁剪机制。是否可以将PhotoChooserTask 配置为使用一个特定图像并跳过选择部分?还是有专门针对裁剪的任务?

【问题讨论】:

    标签: image windows-phone-7 windows-phone-8


    【解决方案1】:

    Nokia Imaging SDK 具有一些用于照片裁剪的内置控件。

    这是一个使用CropFilter 类的示例:

    async void CaptureTask_Completed(object sender, PhotoResult e)
    {
        // Create a source to read the image from PhotoResult stream
        using (var source = new StreamImageSource(e.ChosenPhoto))
        {
            // Create effect collection with the source stream
            using (var filters = new FilterEffect(source))
            {
                // Initialize the filter 
                var sampleFilter = new CropFilter(new Windows.Foundation.Rect(0, 0, 500, 500));
    
                // Add the filter to the FilterEffect collection
                filters.Filters = new IFilter[] { sampleFilter };
    
                // Create a target where the filtered image will be rendered to
                var target = new WriteableBitmap((int)ImageControl.ActualWidth, (int)ImageControl.ActualHeight);
    
                // Create a new renderer which outputs WriteableBitmaps
                using (var renderer = new WriteableBitmapRenderer(filters, target))
                {
                    // Render the image with the filter(s)
                    await renderer.RenderAsync();
    
                    // Set the output image to Image control as a source
                    ImageControl.Source = target;
                }
            }
        }
    }
    

    【讨论】:

    • 是的,我知道这一点。问题是这需要一些自定义机制来允许用户选择要裁剪的部分,从而破坏与内置机制的一致性。
    • 明白,但不幸的是没有内置机制来实现你想要的。因此,使用 Nokia Imaging 或创建您自己的模仿 PhotoChooserTask 裁剪的裁剪工具将是您唯一的选择。
    • 没问题。如果这有帮助,请标记为答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 2019-07-19
    • 2017-05-22
    • 1970-01-01
    • 2019-03-14
    • 2012-02-05
    • 1970-01-01
    相关资源
    最近更新 更多