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


C# Imaging.ColorPalette类代码示例

本文整理汇总了C#中System.Drawing.Imaging.ColorPalette的典型用法代码示例。如果您正苦于以下问题:C# ColorPalette类的具体用法?C# ColorPalette怎么用?C# ColorPalette使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ColorPalette类属于System.Drawing.Imaging命名空间,在下文中一共展示了ColorPalette类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MakePalette

        static ColorPalette MakePalette()
        {
            if (palette != null)
                return palette;

            var bmp = new Bitmap(1, 1, PixelFormat.Format4bppIndexed);
            palette = bmp.Palette;
            palette.Entries[0] = Color.FromArgb(0, 0, 0);
            palette.Entries[1] = Color.FromArgb(0, 0, 162);
            palette.Entries[2] = Color.FromArgb(0, 162, 0);
            palette.Entries[3] = Color.FromArgb(0, 162, 162);
            palette.Entries[4] = Color.FromArgb(162, 0, 0);
            palette.Entries[5] = Color.FromArgb(162, 0, 162);
            palette.Entries[6] = Color.FromArgb(170, 85, 0);
            palette.Entries[7] = Color.FromArgb(168, 168, 168);
            palette.Entries[8] = Color.FromArgb(82, 82, 82);
            palette.Entries[9] = Color.FromArgb(80, 80, 255);
            palette.Entries[10] = Color.FromArgb(80, 255, 80);
            palette.Entries[11] = Color.FromArgb(80, 255, 255);
            palette.Entries[12] = Color.FromArgb(255, 80, 80);
            palette.Entries[13] = Color.FromArgb(255, 80, 255);
            palette.Entries[14] = Color.FromArgb(255, 255, 80);
            palette.Entries[15] = Color.FromArgb(255, 255, 255);

            return palette;
        }
开发者ID:half-ogre,项目名称:u4-extractor,代码行数:26,代码来源:Program.cs

示例2: GetPalette

        /// <summary>
        /// Retrieve the palette for the quantized image
        /// </summary>
        /// <param name="palette">Any old palette, this is overrwritten</param>
        /// <returns>The new color palette</returns>
        protected override ColorPalette GetPalette( ColorPalette palette )
        {
            for ( int index = 0 ; index < _colors.Length ; index++ )
                palette.Entries[index] = _colors[index] ;

            return palette ;
        }
开发者ID:adzm,项目名称:BusinessCats,代码行数:12,代码来源:PaletteQuantizer.cs

示例3: _GetColorPalette

 private ColorPalette _GetColorPalette()
 {
     int size = -1;
     int status = SafeNativeMethods.Gdip.GdipGetImagePaletteSize(new HandleRef(this, this.nativeImage), out size);
     if (status != 0)
     {
         throw SafeNativeMethods.Gdip.StatusException(status);
     }
     ColorPalette palette = new ColorPalette(size);
     IntPtr ptr = Marshal.AllocHGlobal(size);
     status = SafeNativeMethods.Gdip.GdipGetImagePalette(new HandleRef(this, this.nativeImage), ptr, size);
     try
     {
         if (status != 0)
         {
             throw SafeNativeMethods.Gdip.StatusException(status);
         }
         palette.ConvertFromMemory(ptr);
     }
     finally
     {
         Marshal.FreeHGlobal(ptr);
     }
     return palette;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:Image.cs

示例4: GetPalette

        /// <summary>
        /// Retrieve the palette for the quantized image
        /// </summary>
        /// <param name="original">Any old palette, this is overrwritten</param>
        /// <returns>The new color palette</returns>
        protected override ColorPalette GetPalette( ColorPalette original )
        {
            // First off convert the octree to _maxColors colors
            ArrayList	palette = _octree.Palletize ( _maxColors - 1 ) ;

            //// Then convert the palette based on those colors
            //for ( int index = 0 ; index < palette.Count ; index++ )
            //	original.Entries[index] = (Color)palette[index] ;

            //// Add the transparent color
            //original.Entries[_maxColors] = Color.FromArgb ( 0 , 0 , 0 , 0 ) ;

            // Then convert the palette based on those colors
            for (int index = 0; index < palette.Count; index++)
            {
                Color TestColor = (Color)palette[index];
                //Test set transparent color when color transparency used
                if (TestColor.ToArgb() == Color.Transparent.ToArgb())
                {
                    TestColor = Color.FromArgb(0, 0, 0, 0);
                }
                original.Entries[index] = TestColor;
            }
            //Clear unused palette entries
            for (int index = palette.Count; index < _maxColors; index++)
            {
                original.Entries[index] = Color.FromArgb(255, 0, 0, 0);
            }
            // Add the transparent color when alpha transparency used
            original.Entries[_maxColors] = Color.FromArgb(0, Color.Transparent);
            return original;
        }
开发者ID:adzm,项目名称:BusinessCats,代码行数:37,代码来源:OctreeQuantizer.cs

示例5: BuildPalette

 private static ColorPalette BuildPalette(ColorPalette palette, PaletteColorHistory[] paletteHistogram)
 {
     for (int paletteColorIndex = 0; paletteColorIndex < paletteHistogram.Length; paletteColorIndex++)
     {
         palette.Entries[paletteColorIndex] = paletteHistogram[paletteColorIndex].ToNormalizedColor();
     }
     return palette;
 }
开发者ID:random-username,项目名称:nQuant,代码行数:8,代码来源:WuQuantizer.cs

示例6: FillPalette

 private void FillPalette(ColorPalette pal)
 {
     int len = pal.Entries.Length;
     for(int i=0; i<len; i++)
     {
         int c = i % 256;
         pal.Entries[i] = Color.FromArgb(c,c,c);
     }
 }
开发者ID:rasberry,项目名称:FileByteColor,代码行数:9,代码来源:DisplayManager.cs

示例7: BuildPalette

        /// <summary>
        /// Builds a color palette from the given <see cref="PaletteColorHistory"/>.
        /// </summary>
        /// <param name="palette">
        /// The <see cref="ColorPalette"/> to fill.
        /// </param>
        /// <param name="paletteHistory">
        /// The <see cref="PaletteColorHistory"/> containing the sum of all pixel data.
        /// </param>
        /// <returns>
        /// The <see cref="ColorPalette"/>.
        /// </returns>
        private static ColorPalette BuildPalette(ColorPalette palette, PaletteColorHistory[] paletteHistory)
        {
            int length = paletteHistory.Length;
            for (int i = 0; i < length; i++)
            {
                palette.Entries[i] = paletteHistory[i].ToNormalizedColor();
            }

            return palette;
        }
开发者ID:AlexSkarbo,项目名称:ImageProcessor,代码行数:22,代码来源:WuQuantizer.cs

示例8: ConverToGifImageWithNewColor

        public static void ConverToGifImageWithNewColor(ref Image refImage, ColorPalette refPalette, Color victimColor, Color newColor)
        {
            ReplaceColorInPalette(ref refImage, refPalette, victimColor, newColor);

            // Rewrite the bitmap data in a new image
            Image gifImage = Core.GifImage.CreateGifImage(ref refImage);

            refImage.Dispose();

            refImage = gifImage;
        }
开发者ID:DeuxHuitHuit,项目名称:ImageColorer-csharp,代码行数:11,代码来源:GifImage.cs

示例9: SpriteFrame

        /// <summary>
        /// Initializes the new sprite frame of the specified size pre-filled with 0xff (transparent byte).
        /// </summary>
        /// <param name="sizeOfSPR">The size in bytes of the frame, including 2 bytes each for height and width</param>
        /// <param name="width">The width of the frame in pixels</param>
        /// <param name="height">The height of the frame in pixels</param>
        /// <param name="palette">The ColorPalette to associate with this frame</param>
        /// <remarks> 
        /// We preset all bytes to 0xff, an unused palette entry that signifies a 
        /// transparent pixel.The default is 0x00, but that's actually used for 
        /// black.This is required due to the manual compression the 7KAA developers
        /// used in the SPR files. See <see cref="SetPixels(FileStream)"/> for the implementation.
        /// </remarks>
        public SpriteFrame(int sizeOfSPR, int width, int height, ColorPalette palette)
        {
            this.SprSize = sizeOfSPR;
            this.Height = height;
            this.Width = width;

            this.PixelSize = this.Height * this.Width;
            this.FrameData = new byte[PixelSize];
            FrameData = Enumerable.Repeat<byte>(0xff, PixelSize).ToArray();
            this.Palette = palette;
        }
开发者ID:sraboy,项目名称:skaa_editor,代码行数:24,代码来源:SpriteFrame.cs

示例10: Bitmap

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

            _scan0 = Marshal.AllocHGlobal(_stride * height);
            _freeScan0 = true;

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

示例11: ConvertTo

 /// <summary>
 /// Конвертация Bitmap в другой формат Bitmap.
 /// </summary>
 /// <param name="source">Источник для конвертации.</param>
 /// <param name="destinationFormat">Новый формат.</param>
 /// <param name="destinationPalette">
 /// Палитра для нового формата, если конечно она нужна для нового формата, иначе передать null.
 /// </param>
 /// <returns>Bitmap в новом формате.</returns>
 public static Bitmap ConvertTo(
     this Bitmap source,
     System.Drawing.Imaging.PixelFormat destinationFormat,
     ColorPalette destinationPalette)
 {
     var result =
         new Bitmap(source.Width, source.Height, destinationFormat);
     if (destinationPalette != null)
         result.Palette = destinationPalette;
     using (Graphics g = Graphics.FromImage(result))
         g.DrawImage(source, 0, 0);
     return result;
 }
开发者ID:wegorich,项目名称:UltimateCommander-WPF-file-Manager,代码行数:22,代码来源:Converter.cs

示例12: GetPalette

        /// <summary> Retrieve the palette for the quantized image. </summary>
        /// <param name="original"> Any old palette, this is overrwritten. </param>
        /// <returns> The new color palette. </returns>
        protected override ColorPalette GetPalette( ColorPalette original ) {
            // First off convert the octree to _maxColors colors
            ArrayList palette = octree.Palletize( maxColors - 1 );

            // Then convert the palette based on those colors
            for( int index = 0; index < palette.Count; index++ )
                original.Entries[index] = (Color)palette[index];

            // Add the transparent color
            original.Entries[maxColors] = Color.FromArgb( 0, 0, 0, 0 );

            return original;
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:16,代码来源:OctreeQuantizer.cs

示例13: GetPalette

 /// <summary>
 /// Retrieve the palette for the quantized image
 /// </summary>
 /// <param name="original">Any old palette, this is overrwritten</param>
 /// <returns>The new color palette</returns>
 protected override ColorPalette GetPalette(ColorPalette original)
 {
     // First off convert the octree to _maxColors colors
     List<Color> palette = this._octree.Palletize(this._maxColors - 1);
     // Then convert the palette based on those colors
     for (int index = 0; index < palette.Count; index++) {
         original.Entries[index] = palette[index];
     }
     for (int i = palette.Count; i < original.Entries.Length; ++i) {
         original.Entries[i] = Color.FromArgb(255, 0, 0, 0);
     }
     // Add the transparent color
     original.Entries[this._maxColors] = Color.FromArgb(0, 0, 0, 0);
     return original;
 }
开发者ID:hksonngan,项目名称:sharptracing,代码行数:20,代码来源:OctreeQuantizer.cs

示例14: PaletteForm

        /// <summary>
        /// Create palette form from ColorPalette.
        /// </summary>
        /// <param name="colPal">Color palette.</param>
        public PaletteForm(bool isTransparent, string name, ColorPalette colPal, UpdatePaletteDelegate palDelegate)
        {
            InitializeComponent();

            this.isTransparentTexture = isTransparent;
            this.Text += name;

            //Backup actual color palette
            originalColorsPalette = new Color[colPal.Entries.Length];
            colPal.Entries.CopyTo(originalColorsPalette, 0);

            //Set color palette
            palette = colPal;
            updatePalette = palDelegate;
        }
开发者ID:Petethegoat,项目名称:HL-Texture-Tools,代码行数:19,代码来源:PaletteForm.cs

示例15: GetSimilarColor

        /// <summary>
        /// Returns Similar color 
        /// </summary>
        /// <param name="palette"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        private static byte GetSimilarColor(ColorPalette palette, Color color)
        {
            byte minDiff = byte.MaxValue;
            byte index = 0;

            for (int i = 0; i < palette.Entries.Length - 1; i++) {

                byte currentDiff = GetMaxDiff(color, palette.Entries[i]);

                if (currentDiff < minDiff) {
                    minDiff = currentDiff;
                    index = (byte)i;
                }
            }

            return index;
        }
开发者ID:XuPeiYao,项目名称:ExcelPixelArt,代码行数:23,代码来源:Convertor1.cs


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