Ejemplo n.º 1
0
        /// <summary>
        /// Creates an image from 32-bit <c>true</c>-color pixels.
        /// </summary>
        /// <param name="pixels">The pixels indexed as [x,y]. [0,0] is top-left.</param>
        /// <param name="format">The image format.</param>
        /// <param name="encoderOptions">The encoder options.</param>
        /// <returns>An <see cref="OxyImage" /></returns>
        public static OxyImage Create(OxyColor[,] pixels, ImageFormat format, ImageEncoderOptions encoderOptions = null)
        {
            var encoder = GetEncoder(format, encoderOptions);
            var image   = new OxyImage(encoder.Encode(pixels));

            // TODO: remove when PNG decoder is implemented
            image.pixels = pixels;

            return(image);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an image from 8-bit indexed pixels.
        /// </summary>
        /// <param name="pixels">The pixels indexed as [x,y]. [0,0] is top-left.</param>
        /// <param name="palette">The palette.</param>
        /// <param name="format">The image format.</param>
        /// <param name="encoderOptions">The encoder options.</param>
        /// <returns>An <see cref="OxyImage" /></returns>
        public static OxyImage Create(
            byte[,] pixels,
            OxyColor[] palette,
            ImageFormat format,
            ImageEncoderOptions encoderOptions = null)
        {
            var encoder = GetEncoder(format, encoderOptions);

            return(new OxyImage(encoder.Encode(pixels, palette)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the <see cref="IImageEncoder" /> for the specified format.
        /// </summary>
        /// <param name="format">The image format.</param>
        /// <param name="encoderOptions">The image encoder options.</param>
        /// <returns>The <see cref="IImageEncoder" />.</returns>
        private static IImageEncoder GetEncoder(ImageFormat format, ImageEncoderOptions encoderOptions)
        {
            switch (format)
            {
            case ImageFormat.Bmp:
                if (encoderOptions == null)
                {
                    encoderOptions = new BmpEncoderOptions();
                }

                if (!(encoderOptions is BmpEncoderOptions))
                {
                    throw new ArgumentException("encoderOptions");
                }

                return(new BmpEncoder((BmpEncoderOptions)encoderOptions));

            case ImageFormat.Png:
                if (encoderOptions == null)
                {
                    encoderOptions = new PngEncoderOptions();
                }

                if (!(encoderOptions is PngEncoderOptions))
                {
                    throw new ArgumentException("encoderOptions");
                }

                return(new PngEncoder((PngEncoderOptions)encoderOptions));

            case ImageFormat.Jpeg:

                throw new NotImplementedException();

            default:
                throw new InvalidOperationException("Image format not supported");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates an image from 8-bit indexed pixels.
 /// </summary>
 /// <param name="pixels">The pixels indexed as [x,y]. [0,0] is top-left.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="format">The image format.</param>
 /// <param name="encoderOptions">The encoder options.</param>
 /// <returns>An <see cref="OxyImage" /></returns>
 public static OxyImage Create(
     byte[,] pixels,
     OxyColor[] palette,
     ImageFormat format,
     ImageEncoderOptions encoderOptions = null)
 {
     var encoder = GetEncoder(format, encoderOptions);
     return new OxyImage(encoder.Encode(pixels, palette));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the <see cref="IImageEncoder" /> for the specified format.
        /// </summary>
        /// <param name="format">The image format.</param>
        /// <param name="encoderOptions">The image encoder options.</param>
        /// <returns>The <see cref="IImageEncoder" />.</returns>
        private static IImageEncoder GetEncoder(ImageFormat format, ImageEncoderOptions encoderOptions)
        {
            switch (format)
            {
                case ImageFormat.Bmp:
                    if (encoderOptions == null)
                    {
                        encoderOptions = new BmpEncoderOptions();
                    }

                    if (!(encoderOptions is BmpEncoderOptions))
                    {
                        throw new ArgumentException("encoderOptions");
                    }

                    return new BmpEncoder((BmpEncoderOptions)encoderOptions);

                case ImageFormat.Png:
                    if (encoderOptions == null)
                    {
                        encoderOptions = new PngEncoderOptions();
                    }

                    if (!(encoderOptions is PngEncoderOptions))
                    {
                        throw new ArgumentException("encoderOptions");
                    }

                    return new PngEncoder((PngEncoderOptions)encoderOptions);

                case ImageFormat.Jpeg:

                    throw new NotImplementedException();

                default:
                    throw new InvalidOperationException("Image format not supported");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates an image from 32-bit <c>true</c>-color pixels.
        /// </summary>
        /// <param name="pixels">The pixels indexed as [x,y]. [0,0] is top-left.</param>
        /// <param name="format">The image format.</param>
        /// <param name="encoderOptions">The encoder options.</param>
        /// <returns>An <see cref="OxyImage" /></returns>
        public static OxyImage Create(OxyColor[,] pixels, ImageFormat format, ImageEncoderOptions encoderOptions = null)
        {
            var encoder = GetEncoder(format, encoderOptions);
            var image = new OxyImage(encoder.Encode(pixels));

            // TODO: remove when PNG decoder is implemented
            image.pixels = pixels;

            return image;
        }