当前位置: 首页>>代码示例>>C#>>正文


C# PixelFormat.IsIndexed方法代码示例

本文整理汇总了C#中PixelFormat.IsIndexed方法的典型用法代码示例。如果您正苦于以下问题:C# PixelFormat.IsIndexed方法的具体用法?C# PixelFormat.IsIndexed怎么用?C# PixelFormat.IsIndexed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PixelFormat的用法示例。


在下文中一共展示了PixelFormat.IsIndexed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Bitmap

        public Bitmap(int width, int height, int stride, PixelFormat pixelFormat, IntPtr scan0)
        {
            _width = width;
            _height = height;
            _stride = stride;
            _pixelFormat = pixelFormat;

            _scan0 = scan0;
            _freeScan0 = false;

            if (pixelFormat.IsIndexed())
                Palette = new ColorPalette(new Color[pixelFormat.GetColorCount()]);
        }
开发者ID:KonstantinFinagin,项目名称:aforge,代码行数:13,代码来源:Bitmap.cs

示例2: Clone

        public Bitmap Clone(PixelFormat pixelFormat)
        {
            List<Color> palette = null;

            // indexed formats require 2 passes - one more pass to determines colors for palette beforehand
            if (pixelFormat.IsIndexed())
            {
                Quantizer.Prepare(this);

                // Pass: scan
                ImageBuffer.ProcessPerPixel(this, null, 4, (passIndex, pixel) =>
                {
                    var color = pixel.GetColor();
                    Quantizer.AddColor(color, pixel.X, pixel.Y);
                    return true;
                });

                // determines palette
                palette = Quantizer.GetPalette(pixelFormat.GetColorCount());
            }

            // Pass: apply
            Image result;
            ImageBuffer.TransformImagePerPixel(this, pixelFormat, palette, out result, null, 4, (passIndex, sourcePixel, targetPixel) =>
            {
                var color = sourcePixel.GetColor();
                targetPixel.SetColor(color, Quantizer);
                return true;
            });

            return (Bitmap)result;
        }
开发者ID:KonstantinFinagin,项目名称:aforge,代码行数:32,代码来源:Bitmap.cs

示例3: Clone

        public Bitmap Clone(PixelFormat pixelFormat)
        {
            if (pixelFormat == this._pixelFormat)
            {
                return new Bitmap(this);
            }

            List<Color> palette = null;

            // indexed formats require 2 passes - one more pass to determines colors for palette beforehand
            if (pixelFormat.IsIndexed())
            {
                var quantizer = new DistinctSelectionQuantizer();
                quantizer.Prepare(this);

                // Pass: scan
                ImageBuffer.ProcessPerPixel(this, null, ParallelTaskCount, (passIndex, pixel) =>
                {
                    var color = pixel.GetColor();
                    quantizer.AddColor(color, pixel.X, pixel.Y);
                    return false;
                });

                // determines palette
                palette = quantizer.GetPalette(pixelFormat.GetColorCount());
            }

            // Pass: apply
            Image result;
            ImageBuffer.TransformImagePerPixel(this, pixelFormat, palette, out result, null, ParallelTaskCount,
                (passIndex, sourcePixel, targetPixel) =>
                {
                    var color = sourcePixel.GetColor();
                    targetPixel.SetColor(color, _quantizer);
                    return true;
                });

            return (Bitmap)result;
        }
开发者ID:jorik041,项目名称:aforge,代码行数:39,代码来源:Bitmap.cs

示例4: TransformPerPixelAdvanced

        public void TransformPerPixelAdvanced(PixelFormat targetFormat, List<Color> palette, out  Image targetImage, IList<Point> path = null, Int32 parallelTaskCount = 4, params TransformPixelAdvancedFunction[] passes)
        {
            // checks parameters
            Guard.CheckNull(targetFormat, "targetFormat");

            // creates a target bitmap in an appropriate format
            targetImage = new Bitmap(Width, Height, targetFormat);

            // sets image palette if needed
            if (targetFormat.IsIndexed()) targetImage.SetPalette(palette);

            // wraps target image to a buffer
            using (ImageBuffer target = new ImageBuffer(targetImage, ImageLockMode.WriteOnly))
            {
                TransformPerPixelBase(target, path, parallelTaskCount, passes);
            }
        }
开发者ID:KonstantinFinagin,项目名称:aforge,代码行数:17,代码来源:ImageBuffer.cs

示例5: ChangePixelFormat

        /// <summary>
        /// Changes the pixel format.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="targetFormat">The target format.</param>
        /// <param name="quantizer">The color quantizer.</param>
        /// <returns>The converted image in a target format.</returns>
        public static Image ChangePixelFormat(this Image image, PixelFormat targetFormat, IColorQuantizer quantizer)
        {
            // checks for image validity
            if (image == null)
            {
                const String message = "Cannot change a pixel format for a null image.";
                throw new ArgumentNullException(message);
            }

            // checks whether a target format is supported
            if (!targetFormat.IsSupported())
            {
                String message = string.Format("A pixel format '{0}' is not supported.", targetFormat);
                throw new NotSupportedException(message);
            }

            // checks whether there is a quantizer for a indexed format
            if (targetFormat.IsIndexed() && quantizer == null)
            {
                String message = string.Format("A quantizer is cannot be null for indexed pixel format '{0}'.", targetFormat);
                throw new NotSupportedException(message);
            }

            // creates an image with the target format
            Bitmap result = new Bitmap(image.Width, image.Height, targetFormat);
            ColorPalette imagePalette = image.Palette;

            // gathers some information about the target format
            Boolean hasSourceAlpha = image.PixelFormat.HasAlpha();
            Boolean hasTargetAlpha = targetFormat.HasAlpha();
            Boolean isSourceIndexed = image.PixelFormat.IsIndexed();
            Boolean isTargetIndexed = targetFormat.IsIndexed();
            Boolean isSourceDeepColor = image.PixelFormat.IsDeepColor();
            Boolean isTargetDeepColor = targetFormat.IsDeepColor();

            // if palette is needed create one first
            if (isTargetIndexed)
            {
                quantizer.Prepare(image);
                image.AddColorsToQuantizer(quantizer);
                Int32 targetColorCount = result.GetPaletteColorCount();
                List<Color> palette = quantizer.GetPalette(targetColorCount);
                result.SetPalette(palette);
            }

            Action<Pixel, Pixel> changeFormat = (sourcePixel, targetPixel) =>
            {
                // if both source and target formats are deep color formats, copies a value directly
                if (isSourceDeepColor && isTargetDeepColor)
                {
                    UInt64 value = sourcePixel.Value;
                    targetPixel.SetValue(value);
                }
                else
                {
                    // retrieves a source image color
                    Color color = isSourceIndexed ? imagePalette.Entries[sourcePixel.Index] : sourcePixel.Color;

                    // if alpha is not present in the source image, but is present in the target, make one up
                    if (!hasSourceAlpha && hasTargetAlpha)
                    {
                        Int32 argb = 255 << 24 | color.R << 16 | color.G << 8 | color.B;
                        color = Color.FromArgb(argb);
                    }

                    // sets the color to a target pixel
                    if (isTargetIndexed)
                    {
                        // for the indexed images, determines a color from the octree
                        Byte paletteIndex = (Byte) quantizer.GetPaletteIndex(color);
                        targetPixel.SetIndex(paletteIndex);
                    }
                    else
                    {
                        // for the non-indexed images, sets the color directly
                        targetPixel.SetColor(color);
                    }
                }
            };

            // process image -> changes format
            image.ProcessImagePixels(result, changeFormat);

            // returns the image in the target format
            return result;
        }
开发者ID:googlecodetogithub,项目名称:denpa-qr-code-editor,代码行数:93,代码来源:Extend.Image.cs


注:本文中的PixelFormat.IsIndexed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。