【发布时间】:2017-12-18 02:59:21
【问题描述】:
本项目基于 Windows10 IoTCore "Hello World"Damo。我想通过纯 rgb 字节数组显示图像。所以我在其中添加了我的代码。
public async void Func()
{
int ret;
uint mode, x, y, width, height;
mode = x = y = width = height = 0;
ret = Roseek_ImageAcquisition_GetResolution(ref mode, ref x, ref y, ref width, ref height);
RunFlag = true;
uint buffsize = width * height * 3;
RawFrameInfo frameinfo = new RawFrameInfo();
byte[] Framebytes = new byte[buffsize];
byte[] bgra = new byte[width * height * 4];
while (RunFlag)
{
ret = Roseek_ImageAcquisition_FetchFrame(Framebytes, buffsize, ref frameinfo, 1000);
if (ret == 0)
{
pFrameToRGB(Framebytes, bgra, (int)width, (int)height);
/* IBuffer ibuf = new Windows.Storage.Streams.Buffer(width * height * 4);
bgra.CopyTo(ibuf);
SoftwareBitmap image = SoftwareBitmap.CreateCopyFromBuffer(ibuf, BitmapPixelFormat.Bgra8, (int)width, (int)height, BitmapAlphaMode.Ignore);
SoftwareBitmapSource sf = new SoftwareBitmapSource();
await sf.SetBitmapAsync(image);*/
using (IRandomAccessStream RandomAccessStream = new InMemoryRandomAccessStream())
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, RandomAccessStream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, width, height, 96, 96, bgra);
await encoder.FlushAsync();
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async () =>
{
var image = new BitmapImage();
await image.SetSourceAsync(RandomAccessStream);
}) ;
}
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
{
HelloMessage.Text = "While Loop! FetchFrame OK!";
});
}
}
一些“Roseek”函数来自另一个 DLL。我认为可能在while循环中添加了一些错误的代码。这个App我调试了很多次,没问题。当我修改并继续远程调试此应用程序时,发生了一些示例错误,例如“Memery out”。之后,我无法永远激活应用程序,但应用程序已安装在物联网设备中。我尝试重启或卸载等我能做的事情应用程序,但不起作用。 我是在 IoTCore 上开发 UWP 的新手。那请问我在循环中添加了一些错误的代码吗?
【问题讨论】:
-
我使用了 Fun() by Task 和 Task.start()
-
这个问题发生后,你能在桌面上调试这个应用程序吗?什么时候出现“内存溢出”错误?你能提供一些详细的信息吗?
-
是的,没有任何错误。但是位置调试环境与远程调试环境不同。我在location调试这个app的时候发现app的进程内存越来越大,甚至比5g还大。所以我认为错误的代码是我的第一个问题。修改此问题后,我将再次远程调试应用程序。
标签: c# visual-studio uwp windows-10-iot-core