简体   繁体   English

从头开始显示位图WPF

[英]Display A Bitmap WPF From Scratch

I've looked at a dozen examples (and tried more than a few) and I can't find a way to easily set up a RenderTargetBitmap or WriteableBitmap in WPF that can go on the Windows store. 我看了十二个示例(并尝试了多个示例),但我找不到在Windows商店中可以轻松地在WPF中设置RenderTargetBitmap或WriteableBitmap的方法。

Eventually I want to directly manipulate an array that I can blt on to the screen at 30 Hz or so. 最终,我想直接操作一个可以以30 Hz左右的速度在屏幕上显示的数组。

This example has probably gotten me the closest: 这个例子可能使我最接近:

DrawingVisual MyDrawingVisual = new DrawingVisual();
//Open its drawing context:
DrawingContext MyDC = MyDrawingVisual.RenderOpen();

// At this point you can draw
Pen p = new Pen();
p.Thickness = 5;
p.Brush = new SolidColorBrush(Colors.Green);
MyDC.DrawLine(p, new Point(1.0, 1.0), new Point(10.0, 10.0));

RenderTargetBitmap MyRenderTargetBitmap = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Default);
MyRenderTargetBitmap.Render(MyDrawingVisual);

RenderTargetBitmap rtbm = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Pbgra32);
rtbm.Render(MyCanvas);

The example above has 2 problems for me: it doesn't seem to draw anything to the screen, and I think MyDC uses DirectX (which I guess doesn't work with the Windows App Store). 上面的示例对我来说有2个问题:它似乎没有在屏幕上绘制任何内容,而且我认为MyDC使用DirectX(我猜它在Windows App Store中不起作用)。

EDIT: 编辑:

This MS example is exactly what I was looking for! 这个MS例子正是我要的!

http://code.msdn.microsoft.com/windowsapps/0f5d56ae-5e57-48e1-9cd9-993115b027b9/sourcecode?fileId=44756&pathId=962809525 http://code.msdn.microsoft.com/windowsapps/0f5d56ae-5e57-48e1-9cd9-993115b027b9/sourcecode?fileId=44756&pathId=962809525

Clemens was right up above. 克莱门斯就在上面。 To me it seems like WPF and XAML are basically the same thing, but they aren't. 在我看来,WPF和XAML基本上是同一回事,但事实并非如此。

My approach above was more or less stabbing around in the dark. 我上面的方法或多或少地在黑暗中刺伤。 I am going to try and use the tutorial as my starting point. 我将尝试以本教程为起点。

http://msdn.microsoft.com/en-us/library/windows/apps/hh986965.aspx http://msdn.microsoft.com/zh-CN/library/windows/apps/hh986965.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM