Ejemplo n.º 1
0
        /// <summary>
        /// Obtener una imagen desde la informacion RAW en formato hexadecimal
        /// </summary>
        /// <param name="hexRaw">RAW en hexadecimal</param>
        /// <param name="pixelFormat">Profundidad en bits</param>
        /// <param name="size">Tamaño de la imagen (ancho x alto)</param>
        /// <returns>Imagen creada</returns>
        public static Bitmap RawToImage(string hexRaw, PixelFormat pixelFormat, Size size)
        {
            Bitmap     bmp = null;
            BitmapData bd  = null;

            try
            {
                int    discarded = 0;
                byte[] raw       = HexEncoding.GetBytes(hexRaw, out discarded);
                bmp = new Bitmap(size.Width, size.Height, pixelFormat);
                bd  = bmp.LockBits(new Rectangle(Point.Empty, size), ImageLockMode.WriteOnly, pixelFormat);
                Marshal.Copy(raw, 0, bd.Scan0, raw.Length);
                return(bmp);
            }
            finally
            {
                if (bd != null)
                {
                    bmp.UnlockBits(bd);
                }
            }
        }