Create Bitmap from byte array - CSharp System.Drawing

CSharp examples for System.Drawing:Image Convert

Description

Create Bitmap from byte array

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Drawing.Imaging;
using System.Drawing;
using System.Collections.Generic;
using System;//  w  w w.j a  v  a  2s.c om

public class Main{
        public static Bitmap CreateBitmap(byte[,] image)
        {
            int xsize = image.GetLength(0);
            int ysize = image.GetLength(1);

            Bitmap b = new Bitmap( xsize , ysize );
            //b.PixelFormat = PixelFormat.Format8bppIndexed;

            for (int x = 0; x < xsize; x++)
            {
                for (int y = 0; y < ysize; y++)
                {
                    Color c = Color.FromArgb(image[x, y], image[x, y], image[x, y]);
                    b.SetPixel( x , y , c );
                }
            }
            return b; 
        }
}

Related Tutorials