How do you convert a byte array to a Bitmap instance (.NET)?

前端 未结 3 788
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 02:14

I am working with cameras (in this case monochrome) in VB.NET. The API of the cameras is in C++ and the manufacturer provides wrappers. As is typical in these cases, the ima

相关标签:
3条回答
  • 2021-01-04 02:59

    Create a valid bitmap header, and preappend it to the byte array. You'll only need to manually create 56-128 bytes of data.

    Second, create a stream from a byte array.

    Next, create an image or bitmap class by using Image.FromStream()/Bitmap.FromStream()

    I wouldn't imagine that there is any sort of raw imaging features in .Net. There is so much needed information for an image, it would be an extremely lengthy parameter list for a method to accept raw bytes and create an imagine (is it a bitmap, jpeg, gif, png, etc, and all the additional data each of those requires to create a valid image) it wouldn't make sense.

    0 讨论(0)
  • 2021-01-04 03:05

    Try this

    var img = new Bitmap(new MemoryStream(yourByteArray));
    
    0 讨论(0)
  • 2021-01-04 03:17

    Seems like all your cameras are of same type, so the images data. I don't know if this is possible in your case, but could you create a this "full bitmap" from any image and then just use header as a template (since it will be same for all images).

    0 讨论(0)
提交回复
热议问题