/// <summary> /// Gets the instance. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public static Image GetInstance(byte[] data) { if ((data == null) || (data.Length < 4)) { throw new ArgumentNullException("data"); } byte num = data[0]; byte num2 = data[1]; byte num3 = data[2]; byte num4 = data[3]; for (int i = 0; i < _ImageTypes.Length; i++) { System.Type type = _ImageTypes[i]; // hdt Type ctParam = typeof(byte); if (!type.GetTypeInfo().IsAbstract && (((type == typeof(GifImage)) || (type == typeof(PngImage))) || ((type == typeof(BitmapImage)) || type.GetTypeInfo().IsSubclassOf(typeof(Image)))) && ((bool)type.GetRuntimeMethod("CheckType", new Type[] { ctParam, ctParam, ctParam, ctParam }).Invoke(null, new object[] { (byte)num, (byte)num2, (byte)num3, (byte)num4 }))) { if (type == typeof(GifImage)) { GifImage image = (GifImage)Activator.CreateInstance(type, new object[] { data }); return(image.GetImage(1)); } if (type == typeof(PngImage)) { return(PngImage.GetImage(data)); } if (type == typeof(BitmapImage)) { return(BitmapImage.GetImage(data)); } return((Image)Activator.CreateInstance(type, new object[] { data })); } } throw new PdfUnrecognizedImageFormatException("Not a recognized Image Format."); }
/// <summary> /// Reads a PNG from a stream. /// </summary> /// <param name="stream"></param> /// <returns></returns> public static Image GetImage(Stream stream) { PngImage image = new PngImage(stream); return(image.GetImage()); }