• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Imaging.ColorPalette类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ConvertTo8bpp

 /// <summary>Converts a Bitmap to PixelFormat.Format8bppIndexed using the given palette.</summary>
 /// <remarks>Primary overload.</remarks>
 /// <param name="image">The image to be converted.</param>
 /// <param name="palette">The palette to be used.</param>
 /// <returns>A Bitmap with PixelFormat.Format8bppIndexer.</returns>
 public static Bitmap ConvertTo8bpp(Bitmap image, ColorPalette palette)
 {
     image = new Bitmap(image);	// convert to 32bppRGB
     Bitmap new8bit = new Bitmap(image.Width, image.Height, PixelFormat.Format8bppIndexed);
     BitmapData bd32 = GetBitmapData(image);
     byte[] pix32 = new byte[bd32.Stride * bd32.Height];
     CopyImageToBytes(bd32, pix32);	// 32bppImage to Bytes
     BitmapData bd8 = GetBitmapData(new8bit);
     byte[] pix8 = new byte[bd8.Stride * bd8.Height];
     for (int y = 0; y < image.Height; y++)
         for (int x = 0, pos32 = y*bd32.Stride, pos8 = y*bd8.Stride; x < image.Width; x++)
             pix8[pos8+x] = PaletteIndex(pix32[pos32+x*4+2], pix32[pos32+x*4+1], pix32[pos32+x*4], palette);
     CopyBytesToImage(pix8, bd8);	// Bytes to 8bppImage
     image.UnlockBits(bd32);
     new8bit.UnlockBits(bd8);
     new8bit.Palette = palette;
     return new8bit;
 }
开发者ID:MikeG621,项目名称:Common,代码行数:23,代码来源:GraphicsFunctions.cs


示例17: ColorPaletteToLookupTable

        /// <summary>
        /// Convert the color pallette to four lookup tables
        /// </summary>
        /// <param name="pallette">The color pallette to transform</param>
        /// <param name="bTable">Lookup table for the B channel</param>
        /// <param name="gTable">Lookup table for the G channel</param>
        /// <param name="rTable">Lookup table for the R channel</param>
        /// <param name="aTable">Lookup table for the A channel</param>
        public static void ColorPaletteToLookupTable(ColorPalette pallette, out Matrix<Byte> bTable, out Matrix<Byte> gTable, out Matrix<Byte> rTable, out Matrix<Byte> aTable)
        {
            bTable = new Matrix<byte>(256, 1);
             gTable = new Matrix<byte>(256, 1);
             rTable = new Matrix<byte>(256, 1);
             aTable = new Matrix<byte>(256, 1);
             byte[,] bData = bTable.Data;
             byte[,] gData = gTable.Data;
             byte[,] rData = rTable.Data;
             byte[,] aData = aTable.Data;

             Color[] colors = pallette.Entries;
             for (int i = 0; i < colors.Length; i++)
             {
            Color c = colors[i];
            bData[i, 0] = c.B;
            gData[i, 0] = c.G;
            rData[i, 0] = c.R;
            aData[i, 0] = c.A;
             }
        }
开发者ID:wendellinfinity,项目名称:ShoulderSurferAlert,代码行数:29,代码来源:CvToolbox.cs


示例18: ColorsForm

 public ColorsForm(ref ColorPalette palette, int numberOfColors)
 {
     InitializeComponent();
     Height = 316;
     _palette = palette;
     _numberOfColors = numberOfColors;
     for (int y=0, i=0;y<16;y++)
         for (int x=0;(x<16 && i<_numberOfColors);x++, i++)
         {
             pnlColors[i] = new Panel();
             pnlColors[i].Tag = i;
             pnlColors[i].Click += new EventHandler(pnlColors_Click);
             pnlColors[i].MouseEnter += new EventHandler(pnlColors_MouseEnter);
             pnlColors[i].Size = new Size(16, 16);
             pnlColors[i].Left = x*16 + 20;
             pnlColors[i].Top = y*16 + 20;
             pnlColors[i].BackColor = _palette.Entries[i];
             pnlColors[i].BorderStyle = BorderStyle.FixedSingle;
             this.Controls.Add(pnlColors[i]);
         }
     lblCount.Text = "Color Count: " + _numberOfColors;
 }
开发者ID:MikeG621,项目名称:XwingActEditor,代码行数:22,代码来源:ColorsForm.cs


示例19: 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 abstract ColorPalette GetPalette ( ColorPalette original ) ;
开发者ID:rlugojr,项目名称:Alferd-Spritesheet-Unpacker,代码行数:6,代码来源:Quantizer.cs


示例20: ConvertColorPalette

 private static void ConvertColorPalette(ColorPalette destPalette, BitmapPalette bitmapPalette)
 {
     System.Drawing.Color[] entries = destPalette.Entries;
     IList<System.Windows.Media.Color> colors = bitmapPalette.Colors;
     if (entries.Length < colors.Count)
         throw new ArgumentException("Destination palette has less entries than the source palette");
     int index = 0;
     for (int count = colors.Count; index < count; ++index)
         entries[index] = DataObjectExtensions.ToDrawingColor(colors[index]);
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:10,代码来源:DataObjectExtensions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Imaging.EncoderParameter类代码示例发布时间:2022-05-26
下一篇:
C# Imaging.ColorMatrix类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap