public BitmapRam ToBitmapRam() { var result = new BitmapRam(Width, Height); result.CopyPixelsFrom(this); return(result); }
public static BitmapRam ToBitmapRam(this BitmapSource src) { var result = new BitmapRam(src.PixelWidth, src.PixelHeight); result.CopyPixelsFrom(src); return(result); }
/// <summary>Loads a .tga image directly into a <see cref="BitmapRam"/> instance.</summary> public static BitmapRam Load(Stream file) { var header = file.Read(18); if (header[0] != 0) { throw new NotSupportedException("Only images with no offset are supported"); } if (header[1] != 0) { throw new NotSupportedException("Only RGB images are supported"); } if (header[2] != 2) { throw new NotSupportedException("Only RGB images are supported"); } if (header[8] != 0 || header[9] != 0 || header[10] != 0 || header[11] != 0) { throw new NotSupportedException("Only images with origin at 0,0 are supported"); } var width = (header[13] << 8) + header[12]; var height = (header[15] << 8) + header[14]; if (width > 2048 || height > 2048) // an arbitrary limit; more for sanity check than anything else { throw new NotSupportedException("Only images up to 2048x2048 are supported"); } if (width == 0 || height == 0) { throw new NotSupportedException("Images with a zero width or height are not supported"); } if (header[16] != 32) { throw new NotSupportedException("Only 32 bits per pixel images are supported"); } bool rightWayUp = (header[17] & 32) != 0; var raw = file.Read(width * height * 4); var result = new BitmapRam(width, height); result.CopyPixelsFrom(raw, width, height, width * 4, !rightWayUp); return(result); }
/// <summary>Loads a .tga image directly into a <see cref="BitmapRam"/> instance.</summary> public static BitmapRam Load(Stream file) { var header = file.Read(18); if (header[0] != 0) throw new NotSupportedException("Only images with no offset are supported"); if (header[1] != 0) throw new NotSupportedException("Only RGB images are supported"); if (header[2] != 2) throw new NotSupportedException("Only RGB images are supported"); if (header[8] != 0 || header[9] != 0 || header[10] != 0 || header[11] != 0) throw new NotSupportedException("Only images with origin at 0,0 are supported"); var width = (header[13] << 8) + header[12]; var height = (header[15] << 8) + header[14]; if (width > 2048 || height > 2048) // an arbitrary limit; more for sanity check than anything else throw new NotSupportedException("Only images up to 2048x2048 are supported"); if (width == 0 || height == 0) throw new NotSupportedException("Images with a zero width or height are not supported"); if (header[16] != 32) throw new NotSupportedException("Only 32 bits per pixel images are supported"); bool rightWayUp = (header[17] & 32) != 0; var raw = file.Read(width * height * 4); var result = new BitmapRam(width, height); result.CopyPixelsFrom(raw, width, height, width * 4, !rightWayUp); return result; }
public BitmapRam ToBitmapRam() { var result = new BitmapRam(Width, Height); result.CopyPixelsFrom(this); return result; }
public static BitmapRam ToBitmapRam(this BitmapSource src) { var result = new BitmapRam(src.PixelWidth, src.PixelHeight); result.CopyPixelsFrom(src); return result; }