Array ByteArray in MemoryStream

I have a method that returns a ByteArray array:

public byte[][] Draw(ImageFormat imageFormat, ImageSize imageSize);

and I need to write it to MemoryStream:

var byteArray = instanceName.Draw(ImageFormat.Jpeg, ImageSize.Dpi150);
MemoryStream ms = new MemoryStream(byteArray[0]);

This still works because the byteArray array has only one element. Can anyone point out and provide a solution: what happens if the byteArray has more than one element?

I assume that with the current code, I would still take the first byteArray element and discard the rest, but I need MemoryStreamit and it cannot accept a multidimensional array.

+3
source share
2 answers

iYou have to write and write, for example:

var ms = new MemoryStream();
for(var i=0; i < byteArray.Length; i++)
  ms.Write(byteArray[i], 0, byteArray[i].Length);

( , , , , , )

+1

, [0] . , , . , Draw() , ( ), - .

0

Source: https://habr.com/ru/post/1771214/


All Articles