/// <summary> /// Loads byte array from a bitmap /// </summary> /// <param name="bmp">Bitmap with byte data</param> /// <returns>true if image loaded successfully, otherwise false</returns> public bool Load(Bitmap bmp) { bool status = true; try { Width = bmp.Width; Height = bmp.Height; Depth = (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) ? 1 : 3; if (Depth == 1) { BitmapUtility.CopyBitmapToMonochromeBytes(bmp, ref data); } else { BitmapUtility.Copy24bppBitmapToColorBytes(bmp, out data); } } catch { status = false; } return(status); }
/// <summary> /// Returns the byte array data in the form of a Bitmap /// </summary> /// <returns>Bitmap</returns> public Bitmap GetBitmap() { if (data.Length < 10) { return(null); } Bitmap bmp = null; if (Depth == 1) { BitmapUtility.CopyBytesTo8bppBitmap(Width, Height, data, ref bmp); } else { bmp = BitmapUtility.CopyColorBytesTo24bppBitmap(Width, Height, Depth, data); } return(bmp); }