/// <summary>Converts an array of bytes to a Bitmap object</summary> /// <param name="bytes"> /// Bytes for the bitmap, typically read from a resource. This is the complete bitmap /// structure starting with the BITMAPFILEHEADER, etc... as appropriate for the image /// file type. /// </param> /// <remarks> /// Converts an array of bytes, typically retrieved from a resource, into a Bitmap /// instance. The bytes are scanned to determine the correct type of bitmap to /// create (Windows Bitmap, GIF, JPEG) /// </remarks> /// <returns>Converted Bitmap</returns> public static Bitmap ByteArrayToBitmap(byte[] bytes) { Bitmap.BitmapImageType imageType = Bitmap.BitmapImageType.Bmp; if (bytes == null) { throw new ArgumentNullException("bytes"); } int len = bytes.Length; // test for BMP file signature ('BM') if (((len < 2) || (bytes[0] != 0x42)) || (bytes[1] != 0x4d)) { // Check for GIF signature if (((len < 3) || (bytes[0] != 0x47)) || ((bytes[1] != 0x49) || (bytes[2] != 70))) { // Check for JPG signature if ((((len < 10) || (bytes[6] != 0x4a)) || ((bytes[7] != 70) || (bytes[8] != 0x49))) || (bytes[9] != 70)) { throw new ArgumentException("Invalid image type"); } imageType = Bitmap.BitmapImageType.Jpeg; } imageType = Bitmap.BitmapImageType.Gif; } return(new Bitmap(bytes, imageType)); }
private static Bitmap LoadImage(string filePath, Bitmap.BitmapImageType imageType) { return(new Bitmap(File.ReadAllBytes(filePath), imageType)); }
/// <summary> /// Displays an image from a file on the screen. /// </summary> /// <param name="filePath">The path to the image file.</param> /// <param name="imageType">The type of image contained in <paramref name="filePath"/>.</param> /// <param name="x">Horizontal position of the left edge of the image on the display.</param> /// <param name="y">Vertical position of the top edge of the image on the display.</param> public void DisplayImage(string filePath, Bitmap.BitmapImageType imageType, uint x, uint y) { Bitmap bitmap = LoadImage(filePath, imageType); DisplayImage(bitmap, x, y, 0, 0, (uint)bitmap.Width, (uint)bitmap.Height); }
/// <summary> /// Displays an image from a file on the screen. /// </summary> /// <param name="filePath">The path to the image file.</param> /// <param name="imageType">The type of image contained in <paramref name="filePath"/>.</param> /// <param name="x">Horizontal position of the left edge of the image on the display.</param> /// <param name="y">Vertical position of the top edge of the image on the display.</param> /// <param name="xSrc">Source X coordinate. Use this parameter to specify cropping from the left edge of the image. Use 0 to display full image.</param> /// <param name="ySrc">Source Y coordinate. Use this parameter to specify cropping from the top edge of the image. Use 0 to display full image.</param> /// <param name="width">Source width. Use this parameter to specify cropping to the right of the image. Use bitmap.Width to display full image.</param> /// <param name="height">Source height. Use this parameter to specify cropping to the right of the image. Use bitmap.Height to display full image.</param> public void DisplayImage(string filePath, Bitmap.BitmapImageType imageType, uint x, uint y, uint xSrc, uint ySrc, uint width, uint height) { Bitmap bitmap = LoadImage(filePath, imageType); DisplayImage(bitmap, x, y, xSrc, xSrc, width, height); }
public DisplayModule.ResourceImageSprite AddResourceImageSprite(System.Resources.ResourceManager resourceMgr, System.Enum resourceID, Bitmap.BitmapImageType imageType, int x, int y) { var retval = new ResourceImageSprite(this, x, y, resourceMgr, resourceID, imageType); AddSprite(retval); return(retval); }
public ResourceImageSprite(DisplayModule container, int x, int y, System.Resources.ResourceManager resourceMgr, System.Enum resourceID, Bitmap.BitmapImageType imageType) : base(container, x, y) { _resourceMgr = resourceMgr; _resourceID = resourceID; _imageType = imageType; }
/// <summary> /// Gets an image object from the specified file. /// </summary> /// <param name="filePath">The path to file that contains the image, relative to the storage device root directory.</param> /// <param name="imageType">The type of image contained in the file.</param> /// <returns>The image.</returns> public Bitmap LoadBitmap(string filePath, Bitmap.BitmapImageType imageType) { return new Bitmap(File.ReadAllBytes(RootDirectory + Path.DirectorySeparatorChar + filePath), imageType); }
internal static Bitmap GetBitmap(Resources.BinaryResources id, Bitmap.BitmapImageType type) { return(new Bitmap(Resources.GetBytes(id), type)); }
/// <summary> /// Gets an image object from the specified file. /// </summary> /// <param name="filePath">The path to file that contains the image, relative to the storage device root directory.</param> /// <param name="imageType">The type of image contained in the file.</param> /// <returns>The image.</returns> public Bitmap LoadBitmap(string filePath, Bitmap.BitmapImageType imageType) { return(new Bitmap(File.ReadAllBytes(Path.Combine(RootDirectory, filePath)), imageType)); }