How to Convert 2-D array into Image in c#

后端 未结 5 754
忘掉有多难
忘掉有多难 2020-12-11 05:57

I have a 2D array of integers in c#.

Each entry in the 2-D array correspond to a pixel value

How can i make this 2-D array into an image file (in C#)

<
5条回答
  •  误落风尘
    2020-12-11 06:47

    If you have the need for speed look at my Kinect sample. Basically it creates a memory area and uses an unsafe pointer to generate an Int32 array towards the memory. A BitmapSource object is used to map a bitmap (image) directly onto the same area. This particular example also uses unmanaged memory to make it compatible with P/Invoke.

    This blogpost describes the difference in performance of using unsafe. Part from that have a look at:

    • http://www.bytemycode.com/snippets/snippet/412/
    • http://www.jmsoftware.co.uk/blog/c-snippet-for-accessing-bitmap-data-with-unsafe-code
    • http://www.vcskicks.com/fast-image-processing.php

    Note that you can just as well make a Int32[]-pointer instead of the examples which uses Byte[]-pointer.

提交回复
热议问题