/// <summary> Create Color[] from PNG file, async </summary> public static async Task <ReadColorsResult> ReadColorsAsync ( string filePath ) { ReadColorsResult results = new ReadColorsResult { pixels = null, width = -1, height = -1, textureFormatInfered = 0 }; PngReader reader = null; try { reader = FileHelper.CreatePngReader(filePath); var info = reader.ImgInfo; results.height = info.Rows; results.width = info.Cols; results.pixels = new Color[results.width * results.height]; int channels = info.Channels; int bitDepth = info.BitDepth; //select appropriate texture format: results.textureFormatInfered = GetTextureFormat(bitDepth, channels, info.Indexed); //create pixel array: await Task.Run(() => { ReadSamples(reader, results); }); } catch (System.Exception ex) { Debug.LogException(ex); if (results.pixels == null) { results.width = 2; results.height = 2; results.pixels = new Color[results.width * results.height]; } if (results.textureFormatInfered == 0) { results.textureFormatInfered = TextureFormat.RGBA32; } } finally { if (reader != null) { reader.Dispose(); } } return(results); }
/// <summary> Creates ImageInfo object based on given png </summary> public static ImageInfo ReadImageInfo ( string filePath ) { ImageInfo imageInfo = null; PngReader reader = null; try { reader = FileHelper.CreatePngReader(filePath); imageInfo = reader.ImgInfo; } catch (System.Exception ex) { Debug.LogException(ex); } finally { if (reader != null) { reader.Dispose(); } } return(imageInfo); }