How to convert bitmap to byte array?

By [)ia6l0 iii

To convert a bitmap to byte array, use the MemoryStream's ToArray Method.

Code sample:

byte[] data = default(byte[]);
using(System.IO.MemoryStream sampleStream = new System.IO.MemoryStream())
{
  
//save to stream.
myBitmap.Save (sampleStream, System.Drawing.Imaging.ImageFormat.Bmp);

    //
the byte array
    
data = sampleStream.ToArray();
}

How to convert bitmap to byte array?To convert a bitmap to byte array, use the MemoryStream's ToArray Method.

Related FAQs

Exception.ToString() contains a detailed description of the Exception with its stack trace. The Message property of the Exception object contains the smaller version of the description.
C# 4.0 provides us a new type of generics - Tuples
Named and optional parameters is a new concept introduced in 4.0. The Named Parameters allow you to pass arguments by parameter name instead of parameter position in the signature. Optional Parameters allow parameters to be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted.
You can truncate the file paths using the Shell LightWeight library.
The IndexOf method in C# is case -sensitive. However, you can use the CompareInto class to make it insensitive to case.
You can read a text file into a string. But practically speaking, not sure why one would do this.
How to convert bitmap to byte array?  (5505 Views)