image processing - Convert int[] to byte[] type pointer in C# -
i require convert int[] byte[] pointer. above required in order able populate entries of writeablebitmap pixel pixel below:
//previewbuffer1 of type byte[] writeablebitmap wb1 = new writeablebitmap(nvidwidth, nvidheight); int k=0; // wb1.pixels of type int[] default byte* data = (byte*) wb1.pixels; // ****this doesn't work. throws error. how can accomplish this*** (int i=0; i<nvidheight; i++){ (int j=0; j<nvidwidth; j++){ byte grayscaleval = previewbuffer1[k]; data [4*k] = grayscaleval ; data [4*k + 1] = grayscaleval ; data [4*k + 2] = grayscaleval ; k++; } }
how byte* pointer wb1.pixels of type int[]?
sounds want treat each int
in array sequence of bytes - how bitconverter.getbytes
?
byte[] bytes = bitconverter.getbytes(intvalue);
if want avoid array copying etc, use unsafe
allows pointers (you'd need tick "allow unsafe code" checkbox in project properties):
unsafe static void unsafeconvert(int value) { byte* bytes = (byte*)&value; byte first = bytes[0]; ... }
Comments
Post a Comment