/// <summary> /// Obtener la informacion RAW en hexadecimal de la imagen /// </summary> /// <param name="bmBitmap"></param> /// <returns></returns> public static string ImageToRaw(Bitmap bmBitmap) { System.Drawing.Imaging.BitmapData raw = null; //used to get attributes of the image byte[] rawImage = null; //the image as a byte[] try { if (bmBitmap.PixelFormat != PixelFormat.Format1bppIndexed) { bmBitmap = Monocrome(bmBitmap, false); } //'Freeze the image in memory raw = bmBitmap.LockBits(new Rectangle(0, 0, bmBitmap.Width, bmBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format1bppIndexed); int size = raw.Height * raw.Stride; rawImage = new byte[size]; //Copy the image into the byte() System.Runtime.InteropServices.Marshal.Copy(raw.Scan0, rawImage, 0, size); return(HexEncoding.ToString(rawImage)); } finally { if (raw != null) { //'Unfreeze the memory for the image bmBitmap.UnlockBits(raw); } } }
public static string ImageToRaw(Bitmap bmBitmap) { BitmapData bitmapdata = (BitmapData)null; try { if (bmBitmap.PixelFormat != PixelFormat.Format1bppIndexed) { bmBitmap = PrintingUtils.Monocrome(bmBitmap, false); } bitmapdata = bmBitmap.LockBits(new Rectangle(0, 0, bmBitmap.Width, bmBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format1bppIndexed); int length = bitmapdata.Height * bitmapdata.Stride; byte[] numArray = new byte[length]; Marshal.Copy(bitmapdata.Scan0, numArray, 0, length); return(HexEncoding.ToString(numArray)); } finally { if (bitmapdata != null) { bmBitmap.UnlockBits(bitmapdata); } } }