通过线程渲染位图
我正在从许多像素中产生镜头。问题是将其呈现为0.8秒。我想通过螺纹实现这一目标,以免冻结我的GUI。
我很笨拙。我尝试了许多方法,但我无法正常工作。
我只需要这种方法才能工作,应该没事。
volatile DrawingVisual dv = new DrawingVisual();
volatile RenderTargetBitmap rtb;
volatile DrawingContext dc;
private async Task<Image> GetSpectogram(List<int[]> Lines)
{
using (dc = dv.RenderOpen())
{
int y = -1;
int x = -1;
foreach (int[] list in Lines)
{
x += 1;
for (int i = 0; i < list.Length; i++)
{
y += 1;
int value = list[i];
dc.DrawRectangle(GetRGBFromValue(value), null, new Rect(x, y, 1, 1));
}
y = -1;
}
dc.Close();
}
await Task.Factory.StartNew(() => {
rtb = new RenderTargetBitmap(TotalLines, TotalPixelsInLine, 0, 0, PixelFormats.Default);
rtb.Render(dv);
Image img = new Image();
img.Source = rtb;
img.Height = rtb.Height * 3;
img.VerticalAlignment = VerticalAlignment.Stretch;
img.Stretch = Stretch.Uniform;
return img;
});
return null;
}
您能告诉我这里有什么问题,我想理解吗? 它在rtb.render(dv)上扔螺纹错误;
非常感谢 :)
I'm generating spectogram out of many pixels. Problem is that it takes 0.8 second to render it. I would like to achieve that with threading so It doesn't freeze my GUI.
I'm very clueless. I tried many approaches but I can't get it working.
I need only this method to work and it should be fine.
volatile DrawingVisual dv = new DrawingVisual();
volatile RenderTargetBitmap rtb;
volatile DrawingContext dc;
private async Task<Image> GetSpectogram(List<int[]> Lines)
{
using (dc = dv.RenderOpen())
{
int y = -1;
int x = -1;
foreach (int[] list in Lines)
{
x += 1;
for (int i = 0; i < list.Length; i++)
{
y += 1;
int value = list[i];
dc.DrawRectangle(GetRGBFromValue(value), null, new Rect(x, y, 1, 1));
}
y = -1;
}
dc.Close();
}
await Task.Factory.StartNew(() => {
rtb = new RenderTargetBitmap(TotalLines, TotalPixelsInLine, 0, 0, PixelFormats.Default);
rtb.Render(dv);
Image img = new Image();
img.Source = rtb;
img.Height = rtb.Height * 3;
img.VerticalAlignment = VerticalAlignment.Stretch;
img.Stretch = Stretch.Uniform;
return img;
});
return null;
}
Can you please tell me what is the problem here, I would like to understand it?
It is throwing threading error at rtb.Render(dv);
Thank you very much :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论