【问题标题】:HRESULT: 0x8004C00F while using Nokia Imaging sdkHRESULT:0x8004C00F 使用 Nokia Imaging sdk 时
【发布时间】:2014-12-19 16:26:17
【问题描述】:

这是代码的外观。

void ApplyFilter()
{
    this.filterOperationInProgress = true;
    WriteableBitmap wBmp = new WriteableBitmap(0, 0);
    wBmp = LocalWriteableBitmap.Clone();
    NokiaFilters nf = new NokiaFilters(wBmp, FilterName.Mango);
    wBmp = nf.render().Result;
    this.filterOperationInProgress = false;
}

诺基亚过滤器类:

class NokiaFilters
{
    WriteableBitmap wb;
    FilterName filtername = FilterName.NoFilter;
    public NokiaFilters(WriteableBitmap wbm1, FilterName filtername1)
    {
        wb = wbm1;
        filtername = filtername1;
    }

    public async Task<WriteableBitmap> render()
    {
        MemoryStream memstream = new MemoryStream(wb.ToByteArray());
        if (memstream == null)
            return wb;
        //Mango
        else if (filtername == FilterName.Mango)
        {
            memstream.Position = 0;
            // Create a source to read the image from PhotoResult stream
            using (var source = new StreamImageSource(memstream))
            {
                // Create effect collection with the source stream
                using (var filters = new FilterEffect(source))
                {
                    // Initialize the filter 
                    ContrastFilter contrastfilter = new ContrastFilter(0.16);
                    HueSaturationFilter saturationfilter = new HueSaturationFilter(-0.01, -0.53);

                    LomoFilter lomofilter = new LomoFilter(0.5, 0.5, LomoVignetting.Low, LomoStyle.Yellow);
                    // Add the filter to the FilterEffect collection
                    filters.Filters = new List<IFilter> { contrastfilter, saturationfilter, lomofilter };

                   // Create a target where the filtered image will be rendered to
                   var target = new WriteableBitmap((int)wb.PixelWidth, (int)wb.PixelHeight);

                   // Create a new renderer which outputs WriteableBitmaps
                   using (var renderer = new WriteableBitmapRenderer( filters,target))
                   {
                       // Render the image with the filter(s)
                       try
                       {
                           target  = await renderer.RenderAsync().AsTask().ConfigureAwait(false);                                                            
                       }
                       catch (System.InvalidOperationException inv)
                       { }
                       catch { }

                       // Set the output image to Image control as a source
                       return target;
                   }
               }
           }
       }

       return wb;
   }
}

我的 UI 完全卡住了,甚至后退按钮也没有响应。当我停止调试器时,代码指向

wBmp = nf.render().Result;

在这种情况发生之前开始执行的语句是

target  = await renderer.RenderAsync().AsTask().ConfigureAwait(false);

我是并行编程的新手。我搜索了很多,发现死锁在这种情况下很常见。我相信这也是一个死锁的情况。我该如何解决这个问题?

更新:

替换后

wBmp = nf.render().Result;

wBmp = await nf.render().ConfigureAwait(false);

我收到 HRESULT: 0x8004C00F 错误在 catch {} 之后

target  = await renderer.RenderAsync().AsTask().ConfigureAwait(false);

这是堆栈跟踪:

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Nokia.Graphics.Imaging.WriteableBitmapRenderer.<<RenderAsync>b__0>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at SomeApp.NokiaFilters.<render>d__f.MoveNext()

【问题讨论】:

  • render() 是异步的,所以你最好 await 它的结果。
  • @HenkHolterman 当我使用 await 时,catch {} 捕获了这个异常 HRESULT: 0x8004C00F。我在互联网上没有发现任何关于它的实质性内容。使用 stacktrace 更新帖子。

标签: c# windows-phone-8 deadlock nokia-imaging-sdk lumia-imaging-sdk


【解决方案1】:

解决了。

替换

MemoryStream memstream = new MemoryStream(wb.ToByteArray());

MemoryStream memstream = new MemoryStream(); wb.SaveJpeg(memstream, wb.PixelWidth, wb.PixelHeight, 0, 100);

【讨论】:

    【解决方案2】:

    您是否尝试在没有 ConfigureAwait(false); 的情况下等待? this.filterOperationInProgress 是否与 UI 绑定?如果是这样,可能存在您“更改 UI”而不是在 UI 线程上的情况。

    编辑:wb 是否有效 - PixelWidth 和 PixelHeight 是否大于或等于存储在 MemoryStream 中的图像?

    【讨论】:

    • 我尝试不使用ConfigureAwait(false);,但仍然没有变化,this.filterOperationInProgress 未绑定到 UI,但我将 wBmp 设置为同一功能中某些控件的来源。很抱歉没有包括在内。
    • wb 有 186624 像素数组长度 (int) 和 memorystream 有 746496 (byte) 长度。
    • 我想我知道出了什么问题 - 你使用源 - StreamImageSource 而 MemoryStream 包含 WriteableBitmap 像素数据 - 它不是图像文件数据。尝试将其更改为:“var source = new BitmapImageSource(wb.AsBitmap())”
    • 我认为在内存流中存储了一些不正确的东西。 MemoryStream memstream = new MemoryStream(wb.ToByteArray()); 可能是在memstream中存储图像的错误方式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多