简体   繁体   中英

Proper Control for Rendering in UWP

I am working on implementing my own 3D rendering algorithm, that will ultimately output a 2D set of "pixels", where each pixel is an RGB value. It might look something like:

int pixels[][]

What XAML control would I use to display this data A) as a static image and B) in real-time?

My initial thought conceptually with the static image would be to output my data as a bitmap, and then using an Image control, set the source to that bitmap. So it might look something like this:

int pixels[][] = renderer.Render(sceneData);
Bitmap image = new Bitmap(pixels);
MyImageControl.Source = image;

Is this viable? What is the proper class for a "bitmap"? I am having a hard time finding one. I want to be able to individually manipulate pixel values.

For the second question, real-time, just puts the same code above, but into a loop executing (ideally) 30 to 60 or more times a second, and the output would then be more like a video rather than a single still image. It seems, based on my past UWP and C# experience, that repeatedly setting the Source property of the Image control would be too slow for this.

I can use existing APIs to do things like handle the image data, or display it, or transform it's formats, but the point of this exercise is for me to write my own renderer... so I need to translate input data into a final set of "pixels" myself. I cannot use DirectX or other existing renderers for this.

For you 1st requirement,

What is the proper class for a "bitmap"?

Did you try with CanvasBitmap ? It has static methods like :

CreateFromBytes(ICanvasResourceCreator,Byte[], Int32, Int32, DirectXPixelFormat);

you are to use Byte[] instead of int[] for color info, which is logical.

It has also a method to get raw pixel data:

public byte[] GetPixelBytes()

I want to be able to individually manipulate pixel values.

CanvasBitmap also has these methods to directly set pixel data (from doc:):

  1. SetPixelBytes(Byte[]) Sets the byte data of the bitmap from the specified array.

  2. SetPixelBytes(IBuffer) Sets the byte data of the bitmap from the specified buffer.

  3. SetPixelBytes(Byte[], Int32, Int32, Int32, Int32) Sets the byte data of a subregion of the bitmap.

  4. SetPixelBytes(IBuffer, Int32, Int32, Int32, Int32) Sets the byte data of a subregion of the bitmap from the specified buffer.

For your second requirement:

Do you need to show the video real time? Or just generate a video? There is a solution for generating videos, but not for live showing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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