/// <summary> /// Loads the graphic as a bitmap. <b>Requires System.Drawing.Common</b> /// </summary> /// <returns></returns> public Bitmap LoadImage() { switch (Type) { case GraphicType.Png: case GraphicType.Jpeg: return(new Bitmap(lump.RawStream())); case GraphicType.DoomPatch: return(doomImage.ToImage()); default: throw new ArgumentException("Unsupported image type"); } }
/// <summary> /// Loads a new graphics from a wad /// </summary> /// <param name="lumpName"></param> /// <param name="file"></param> public Graphic(WadFile file, string lumpName) { lump = file[lumpName]; using (MemoryStream stream = lump.RawStream()) { // Move to png marker stream.ReadByte(); bool png = IsPng(stream); bool jfif = false; if (!png) { stream.Position = 4; for (int i = 0; i < 2; i++) { stream.ReadByte(); } jfif = IsJfif(stream); } if (png) { Type = GraphicType.Png; } else if (jfif) { Type = GraphicType.Jpeg; } else { Type = GraphicType.DoomPatch; doomImage = new DoomGraphic(lump, file.Pallete(0)); } } }