Пример #1
0
        /// <summary>
        /// Initializes bitmap object with the specified parameters.
        /// </summary>
        /// <param name="channels">Array of channels</param>
        /// <param name="pixels">Buffer with pixels</param>
        /// <param name="dpiX">The horizontal dots per inch (dpi) of the bitmap.</param>
        /// <param name="dpiY">The vertical dots per inch (dpi) of the bitmap.</param>
        private void Initialize(ChannelType[] channels, ushort[] pixels, double dpiX, double dpiY)
        {
            PixelFormat format;

            // Check format
            if (DefinedChannels.AreSame(channels, DefinedChannels.Grayscale))
            {
                format = PixelFormats.Gray16;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.BGR))
            {
                format = PixelFormats.Rgb48;
                pixels = BGR2RGB(pixels);
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.RGB))
            {
                format = PixelFormats.Rgb48;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.BGRA))
            {
                format = PixelFormats.Rgba64;
                pixels = BGRA2RGBA(pixels);
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.RGBA))
            {
                format = PixelFormats.Rgba64;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.CMYK))
            {
                Initialize(channels, ConvertToByte(pixels), dpiX, dpiY);
                return;
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(channels), $"Unsupported channels: {string.Join(", ", channels)}");
            }

            Initialize(dpiX, dpiY, format, pixels, Width * channels.Length * 2);
        }
Пример #2
0
        /// <summary>
        /// Initializes bitmap object with the specified parameters.
        /// </summary>
        /// <param name="channels">Array of channels</param>
        /// <param name="pixels">Buffer with pixels</param>
        /// <param name="dpiX">The horizontal dots per inch (dpi) of the bitmap.</param>
        /// <param name="dpiY">The vertical dots per inch (dpi) of the bitmap.</param>
        private void Initialize(ChannelType[] channels, byte[] pixels, double dpiX, double dpiY)
        {
            PixelFormat format;

            // Check format
            if (DefinedChannels.AreSame(channels, DefinedChannels.BGR))
            {
                format = PixelFormats.Bgr24;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.BGRA))
            {
                format = PixelFormats.Bgra32;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.CMYK))
            {
                format = PixelFormats.Cmyk32;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.Grayscale))
            {
                format = PixelFormats.Gray8;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.RGB))
            {
                format = PixelFormats.Rgb24;
            }
            else if (DefinedChannels.AreSame(channels, DefinedChannels.RGBA))
            {
                format = PixelFormats.Bgra32;
                pixels = BGRA2RGBA(pixels);
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(channels), $"Unsupported channels: {string.Join(", ", channels)}");
            }

            Initialize(dpiX, dpiY, format, pixels, Width * channels.Length * 1);
        }