Bitmap to int[] using Marshal.Copy()

前端 未结 2 1725
一向
一向 2021-01-13 04:17

I\'m using Marshal.Copy() to copy the pixel information from a Bitmap to an int[] array, the problem resides in the fact that the info

相关标签:
2条回答
  • 2021-01-13 05:11

    Those values are perfectly normal. They are 32bpp pixels with the alpha channel at 0xff, the usual value. In other words: -8682109 == 0xff7b8583. Any alpha value >= 128 will make the value negative because it sets the sign bit.

    Using uint[] instead of int[] can make that easier to see.

    0 讨论(0)
  • 2021-01-13 05:16

    IMHO, your bytecount is a number of byte's and now you're dividing bytes by 4 and expecting a set of integers, that are really bytes. The cast is not performed as you want it.

    To convert a byte array to int array use:

    System.BitConverter.ToInt32(mybyteArray,4);

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