(For bonus points, I'd love to know why the images disappear, but that part is entirely optional. I've long since given up on expecting WinRT to make sense.)推荐答案我做过一些实验,清楚地表明WinRT只是丢失WriteableBitmap的内容,而不是WriteableBitmap本身. WriteableBitmap实例仍然可行.如果您给它新的像素数据,它将正常工作.只是有时候,在应用履历表上,其内容被一大堆透明像素所取代.I've done some experiments that made it clear that WinRT is just losing the contents of the WriteableBitmap, not the WriteableBitmap itself. The WriteableBitmap instance is still viable; if you give it new pixel data, it works fine. It's just that sometimes, on app resume, its contents get replaced with a swath of transparent pixels.通过挂钩应用程序的OnResuming事件,并使用该事件来获取我的WriteableBitmap的PixelBuffer.AsStream(),写入新的像素并调用WriteableBitmap.Invalidate(),我能够解决此问题.如果重新生成图像的代码是同步的,则在应用恢复时图像甚至不会闪烁.I've been able to work around this problem by hooking my app's OnResuming event, and using that event to grab my WriteableBitmap's PixelBuffer.AsStream(), write new pixels, and call WriteableBitmap.Invalidate(). If the code that regenerates the image is synchronous, then the image doesn't even flicker when the app resumes.我怀疑普通位图(通过Source URI加载)也会丢失其像素缓冲区,并且在应用恢复后必须重新加载其像素.图像加载是异步的,这说明了在内容重新出现之前的延迟/闪烁.I suspect that ordinary bitmaps (loaded via a Source URI) are also losing their pixel buffers, and having to reload their pixels after the app resumes. Image loading is async, which explains the delay / flicker before their contents reappear.我还没有找到一种方法来知道图像是否丢失了像素(尽管显然URI加载的图像具有某种了解方式,因为它们会自动重新加载自身).因此,使用WriteableBitmaps,最安全的方法似乎是始终在应用履历表中重新填充它们.I haven't found a way to know whether the image lost its pixels (though obviously URI-loaded images have some way of knowing, since they reload themselves automatically). So with WriteableBitmaps, the safest thing seems to be to always repopulate them on app resume. 这篇关于为什么我的图像有时会在恢复时重新加载(并且WriteableBitmaps消失)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 01:27