Exemplo n.º 1
0
        public Asset(string path)
        {
            this.Path = path;
            this.Path.WithoutQualifier(out string name, out string extension);
            this.FilenameWithoutQualifierAndExtension = name;
            this.Extension = extension;

            if (Densities.TryFind(path, out double foundDensity))
            {
                this.Density = foundDensity;
            }

            using (var input = File.Open(path, FileMode.Open))
                using (var memory = new MemoryStream())
                {
                    input.CopyTo(memory);
                    memory.Seek(0, SeekOrigin.Begin);
                    memory.Position = 0;

                    using (var stream = new SKManagedStream(memory))
                    {
                        this.bitmap = SKBitmap.Decode(stream);

                        if (this.bitmap == null)
                        {
                            throw new InvalidOperationException($"The provided image isn't valid : {path} (SKBitmap can't be created).");
                        }
                    }
                }
        }