當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。