예제 #1
0
        public static ImageInfo?FromStream(Stream stream)
        {
            ImageInfo?info = null;

            if (JpgDecoder.Test(stream))
            {
                info = JpgDecoder.Info(stream);
            }
            else if (PngDecoder.Test(stream))
            {
                info = PngDecoder.Info(stream);
            }
            else if (BmpDecoder.Test(stream))
            {
                info = BmpDecoder.Info(stream);
            }
            else if (GifDecoder.Test(stream))
            {
                info = GifDecoder.Info(stream);
            }
            else if (PsdDecoder.Test(stream))
            {
                info = PsdDecoder.Info(stream);
            }
            else if (TgaDecoder.Test(stream))
            {
                info = TgaDecoder.Info(stream);
            }

            return(info);
        }
예제 #2
0
        public static ImageResult FromStream(Stream stream, ColorComponents?requiredComponents = null,
                                             bool use8BitsPerChannel = true)
        {
            ImageResult result = null;

            if (JpgDecoder.Test(stream))
            {
                result = JpgDecoder.Decode(stream, requiredComponents);
            }
            else if (PngDecoder.Test(stream))
            {
                result = PngDecoder.Decode(stream, requiredComponents);
            }
            else if (BmpDecoder.Test(stream))
            {
                result = BmpDecoder.Decode(stream, requiredComponents);
            }
            else if (GifDecoder.Test(stream))
            {
                result = GifDecoder.Decode(stream, requiredComponents);
            }
            else if (PsdDecoder.Test(stream))
            {
                result = PsdDecoder.Decode(stream, requiredComponents);
            }
            else if (TgaDecoder.Test(stream))
            {
                result = TgaDecoder.Decode(stream, requiredComponents);
            }

            if (result == null)
            {
                Decoder.stbi__err("unknown image type");
            }

            if (use8BitsPerChannel && result.BitsPerChannel != 8)
            {
                result.Data = Conversion.stbi__convert_16_to_8(result.Data, result.Width, result.Height,
                                                               (int)result.ColorComponents);
            }

            return(result);
        }