【问题标题】:How to process high resolution photo in Windows Phone 8.1如何在 Windows Phone 8.1 中处理高分辨率照片
【发布时间】:2014-11-05 17:35:17
【问题描述】:

我正在尝试从 FileOpenPicker 加载图像并将其保存到 WritableBitmap 以便以后使用。它可以工作,但是当我加载高分辨率图像(例如 jpg 2592x3888 )时,我的应用程序崩溃了。而且处理大图像需要很长时间。所以我的问题是:我在这里做错了什么?最好的方法是什么?


StorageFile file = args.Files[0];
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
{
    App.context.Image = new WriteableBitmap(1, 1);
    stream.Seek(0);
    int width = (int)Frame.ActualWidth;
    int height = (int)Frame.ActualHeight;
    App.context.Image = await BitmapFactory.New(1, 1).FromStream(stream);
    App.context.Image = App.context.Image.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
    this.Frame.Navigate(typeof(RecognizingPage));
}

PS:这确实是一个工作版本 - 我不会使用这个宽度和高度。

【问题讨论】:

  • 诺基亚有一个高分辨率图片库(也许这可以帮助你):developer.nokia.com/resources/library/Lumia/imaging/…
  • 谢谢,但“writeableBitmapEx 的问题”仍然存在。在本文中,图像被加载(并解码为更小的)BitmapImage。我想将它加载到 WriteableBitmapEx。有没有一种简单有效的方法来做到这一点? WriteableBitmap 没有 DecodePixelWidth 和 Height :(

标签: image stream windows-phone-8.1 high-resolution writeablebitmapex


【解决方案1】:

您可以使用以下代码来解码图像以获得较低的分辨率。

using (var storageStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, storageStream);
var pixelStream = yourWriteableBitmap.PixelBuffer.AsStream();
var pixels = new byte[pixelStream.Length];
await pixelStream.ReadAsync(pixels, 0, pixels.Length);

encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)yourWriteableBitmap.PixelWidth, (uint)yourWriteableBitmap.PixelHeight, 48, 48, pixels);
await encoder.FlushAsync();
}

您可以参考这个问题了解更多详情: WriteableBitmap SaveJpeg missing for universal apps

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多