示例#1
0
        public async Task <ImageInfo> DecodeAsync(Stream imageStream)
        {
            var output = default(ImageInfo);

            try
            {
                var decoder = await BitmapDecoder.CreateAsync(imageStream.AsRandomAccessStream()).AsTask().ConfigureAwait(false);

                var codecId = decoder.DecoderInformation.CodecId;

                if (codecId == BitmapDecoder.BmpDecoderId)
                {
                    output = ImageInfo.Bmp((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                }
                else if (codecId == BitmapDecoder.GifDecoderId)
                {
                    output = ImageInfo.Gif((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                }
                else if (codecId == BitmapDecoder.JpegDecoderId)
                {
                    output = ImageInfo.Jpeg((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                }
                else if (codecId == BitmapDecoder.PngDecoderId)
                {
                    output = ImageInfo.Png((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                }
            }
            catch
            {
                output = null;
            }

            return(output);
        }
示例#2
0
        public async Task <ImageInfo> DecodeAsync(Stream imageStream)
        {
            var output = default(ImageInfo);

            try
            {
                var format = await Image.DetectFormatAsync(imageStream).ConfigureAwait(false);

                if (format != null)
                {
                    var imageInfo = Image.Identify(imageStream);

                    if (SixLabors.ImageSharp.Formats.Bmp.BmpFormat.Instance.MimeTypes.Contains(format.DefaultMimeType))
                    {
                        output = ImageInfo.Bmp(imageInfo.Width, imageInfo.Height);
                    }
                    else if (SixLabors.ImageSharp.Formats.Gif.GifFormat.Instance.MimeTypes.Contains(format.DefaultMimeType))
                    {
                        output = ImageInfo.Gif(imageInfo.Width, imageInfo.Height);
                    }
                    else if (SixLabors.ImageSharp.Formats.Jpeg.JpegFormat.Instance.MimeTypes.Contains(format.DefaultMimeType))
                    {
                        output = ImageInfo.Jpeg(imageInfo.Width, imageInfo.Height);
                    }
                    else if (SixLabors.ImageSharp.Formats.Png.PngFormat.Instance.MimeTypes.Contains(format.DefaultMimeType))
                    {
                        output = ImageInfo.Png(imageInfo.Width, imageInfo.Height);
                    }
                }
            }
            catch
            {
                output = null;
            }

            return(output);
        }
示例#3
0
        public Task <ImageInfo> DecodeAsync(Stream imageStream)
        {
            var output = default(ImageInfo);

            try
            {
                var decoder = BitmapDecoder.Create(imageStream, BitmapCreateOptions.None, BitmapCacheOption.None);
                if (decoder != null)
                {
                    var frame = decoder.Frames[0];

                    if (decoder is BmpBitmapDecoder)
                    {
                        output = ImageInfo.Bmp(frame.PixelWidth, frame.PixelHeight);
                    }
                    else if (decoder is GifBitmapDecoder)
                    {
                        output = ImageInfo.Gif(frame.PixelWidth, frame.PixelHeight);
                    }
                    else if (decoder is JpegBitmapDecoder)
                    {
                        output = ImageInfo.Jpeg(frame.PixelWidth, frame.PixelHeight);
                    }
                    else if (decoder is PngBitmapDecoder)
                    {
                        output = ImageInfo.Png(frame.PixelWidth, frame.PixelHeight);
                    }
                }
            }
            catch
            {
                output = null;
            }

            return(Task.FromResult(output));
        }