简体   繁体   中英

Convert image to array 2d

I'm need to convert an image to 2D array but I don't know how. I managed to convert it into 1D array so far.

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
     MemoryStream ms = new MemoryStream();
     imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
     return ms.ToArray();
} 
Image image = Image.FromFile("c:\\p01.png");
byte[] mm = imageToByteArray(image);

See the answer to this question: How to convert 1D byte array to 2D byte array which holds a bitmap?

Basically, you want to pass image.Width to the ConvertArray function mentioned in the accepted answer that converts 1D array to 2D array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM