private void Detect(ImageSource imageSource) { IWICImagingFactory iwicimagingFactory = WicUtility.CreateFactory(); IWICBitmapFrameDecode iwicbitmapFrameDecode = iwicimagingFactory.Load(imageSource.ImageStream); this.DetectSalientRegions(iwicimagingFactory, iwicbitmapFrameDecode); GraphicsInteropNativeMethods.SafeReleaseComObject(iwicbitmapFrameDecode); GraphicsInteropNativeMethods.SafeReleaseComObject(iwicimagingFactory); }
protected ImageBase(Stream stream, Guid wicImageFormat) : this() { IWICImagingFactory iwicimagingFactory = WicUtility.CreateFactory(); IWICBitmapFrameDecode iwicbitmapFrameDecode = iwicimagingFactory.Load(stream); this.LoadFromWic(iwicimagingFactory, iwicbitmapFrameDecode, wicImageFormat); GraphicsInteropNativeMethods.SafeReleaseComObject(iwicimagingFactory); GraphicsInteropNativeMethods.SafeReleaseComObject(iwicbitmapFrameDecode); }
public ImageSource(byte[] buffer) { if (buffer == null || buffer.Length == 0) { throw new ArgumentException("Image buffer does not contain a valid image to load.", "buffer"); } this.buffer = buffer; IWICImagingFactory iwicimagingFactory = WicUtility.CreateFactory(); IWICBitmapFrameDecode iwicbitmapFrameDecode = iwicimagingFactory.Load(this.ImageStream); int num; int num2; iwicbitmapFrameDecode.GetSize(out num, out num2); this.Width = (float)num; this.Height = (float)num2; IWICMetadataQueryReader iwicmetadataQueryReader = null; try { iwicbitmapFrameDecode.GetMetadataQueryReader(out iwicmetadataQueryReader); string s; DateTime value; if (iwicmetadataQueryReader.TryGetMetadataProperty("/app1/ifd/exif/subifd:{uint=36867}", out s) && DateTime.TryParseExact(s, "yyyy:MM:dd HH:mm:ss", null, DateTimeStyles.None, out value)) { this.DateTaken = new DateTime?(value); } } catch (Exception) { } try { ushort value2; if (iwicmetadataQueryReader.TryGetMetadataProperty("/app1/ifd/{ushort=274}", out value2)) { this.Orientation = ImageSource.TransformOptionsFromUshort(value2); } else { this.Orientation = WICBitmapTransformOptions.WICBitmapTransformRotate0; } } catch (Exception) { } GraphicsInteropNativeMethods.SafeReleaseComObject(iwicmetadataQueryReader); GraphicsInteropNativeMethods.SafeReleaseComObject(iwicbitmapFrameDecode); GraphicsInteropNativeMethods.SafeReleaseComObject(iwicimagingFactory); }