/// <summary> /// Loads an image from a given file path /// </summary> /// <param name="path">File Path to image</param> /// <param name="bitDepth">bit depth of each pixel</param> /// <param name="isBayered">Flag to indicate if the image is bayer matrix encoded</param> /// <param name="rawConverter">Which type of raw converter to use, when image is in RAW format</param> /// <param name="ct">Token to cancel operation</param> /// <returns></returns> public static Task <IImageData> FromFile(string path, int bitDepth, bool isBayered, RawConverterEnum rawConverter, CancellationToken ct = default(CancellationToken)) { return(Task.Run(async() => { if (!File.Exists(path)) { throw new FileNotFoundException(); } BitmapDecoder decoder; switch (Path.GetExtension(path).ToLower()) { case ".gif": decoder = new GifBitmapDecoder(new Uri(path), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); return await BitmapToImageArray(decoder, isBayered); case ".tif": case ".tiff": decoder = new TiffBitmapDecoder(new Uri(path), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); return await BitmapToImageArray(decoder, isBayered); case ".jpg": case ".jpeg": decoder = new JpegBitmapDecoder(new Uri(path), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); return await BitmapToImageArray(decoder, isBayered); case ".png": decoder = new PngBitmapDecoder(new Uri(path), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); return await BitmapToImageArray(decoder, isBayered); case ".xisf": return await XISF.Load(new Uri(path), isBayered); case ".fit": case ".fits": return await FITS.Load(new Uri(path), isBayered); case ".cr2": case ".cr3": case ".nef": case ".raf": case ".raw": case ".pef": case ".dng": case ".arw": case ".orf": return await RawToImageArray(path, bitDepth, rawConverter, ct); default: throw new NotSupportedException(); } })); }
private string SaveXisf(FileSaveInfo fileSaveInfo) { XISFHeader header = new XISFHeader(); header.AddImageMetaData(Properties, MetaData.Image.ImageType); header.Populate(MetaData); XISF img = new XISF(header); img.AddAttachedImage(Data.FlatArray, fileSaveInfo); Directory.CreateDirectory(Path.GetDirectoryName(fileSaveInfo.FilePath)); string uniquePath = Utility.Utility.GetUniqueFilePath(fileSaveInfo.FilePath + ".xisf"); using (FileStream fs = new FileStream(uniquePath, FileMode.Create)) { img.Save(fs); } return(uniquePath); }