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

C# Color32类代码示例

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

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



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

示例1: QuantizePixel

 /// <summary>
 /// Override this to process the pixel in the second pass of the algorithm
 /// </summary>
 /// <param name="pixel">The pixel to quantize</param>
 /// <param name="destinationPixel"></param>
 /// <returns>The quantized value</returns>
 protected override void QuantizePixel(Color32* pixel, Color32* destinationPixel)
 {
     destinationPixel->Red = pixel->Alpha;
     destinationPixel->Blue = pixel->Alpha;
     destinationPixel->Green = pixel->Alpha;
     destinationPixel->Alpha = 255;
 }
开发者ID:midspace,项目名称:SEToolbox,代码行数:13,代码来源:AlphaPixelEffect.cs


示例2: QuantizePixel

        /// <summary>
        /// Override this to process the pixel in the second pass of the algorithm
        /// </summary>
        /// <param name="pixel">The pixel to quantize</param>
        /// <param name="destinationPixel"></param>
        /// <returns>The quantized value</returns>
        protected override void QuantizePixel(Color32* pixel, Color32* destinationPixel)
        {
            if (pixel->Alpha > 127)
            {
                destinationPixel->Red = pixel->Red;
                destinationPixel->Green = pixel->Green;
                destinationPixel->Blue = pixel->Blue;
                destinationPixel->Alpha = 255;
            }
            else
            {
                int maxColor = pixel->Red;
                if (maxColor < pixel->Green)
                    maxColor = pixel->Green;
                if (maxColor < pixel->Blue)
                    maxColor = pixel->Blue;

                int minColor = pixel->Red;
                if (minColor > pixel->Green)
                    minColor = pixel->Green;
                if (minColor > pixel->Blue)
                    minColor = pixel->Blue;

                var luminance = (byte)((minColor + maxColor) / 2.00f);

                destinationPixel->Red = luminance;
                destinationPixel->Green = luminance;
                destinationPixel->Blue = luminance;

                //destinationPixel->Alpha = 0;
                destinationPixel->Alpha = pixel->Alpha;
            }
        }
开发者ID:midspace,项目名称:SEToolbox,代码行数:39,代码来源:MaskPixelEffect.cs


示例3: drawOnImage

            public override void drawOnImage(ref Image image, ref Image normalMap, BoundingBox boundingBox)
            {
                drawOnImage(ref image, boundingBox);

                if (_normalOption == NormalOption.USE_BACKGROUND) return;

                Image textImage = new Image(image.width, image.height);
                Color32 backgroudColor = new Color32(127, 127, 127, 0);
                textImage.fill(backgroudColor);

                Color32 color = Global.Gray32;
                if (_normalOption == NormalOption.RAISE_TEXT) color = Global.White32;
                if (_normalOption == NormalOption.LOWER_TEXT) color = Global.Black32;

                textImage.drawText(_text, _fontName, _fontSize, _position, _rotation, color, _mirror, AlphaOption.OVERWRITE, 255, BlendMethod.PIXEL);

                BoundingBox bBox = new BoundingBox(boundingBox);
                if (image.width != normalMap.width || image.height != normalMap.height)
                {
                    textImage.rescale(normalMap.width, normalMap.height);
                    bBox.x = (int)((float)bBox.x * (float)normalMap.width / (float)image.width);
                    bBox.w = (int)((float)bBox.w * (float)normalMap.width / (float)image.width);
                    bBox.y = (int)((float)bBox.y * (float)normalMap.height / (float)image.height);
                    bBox.h = (int)((float)bBox.h * (float)normalMap.height / (float)image.height);
                }

                Image normalMapImage = textImage.createNormalMap(_normalScale);
                normalMap.overlay(normalMapImage, textImage, 128, bBox);
            }
开发者ID:panteras1000,项目名称:TheWriteStuff,代码行数:29,代码来源:IM_BitmapText.cs


示例4: Quantize

		public static void Quantize(Bitmap bitmap, Color32[] colorsTable)
		{
			var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
			var colorsDictionary = new Dictionary<Color, Color32>();

			unsafe
			{
				var p = (int*)bitmapData.Scan0.ToPointer();
				for (var i = 0; i < bitmap.Height * bitmap.Width; i++)
				{
					var color = Color.FromArgb(p[i]);

					Color32 closestColor;
					if (!colorsDictionary.TryGetValue(color, out closestColor))
					{
						closestColor = FindClosestColor(color, colorsTable);
						colorsDictionary[color] = closestColor;
					}

					p[i] = closestColor.ARGB;
				}
			}

			bitmap.UnlockBits(bitmapData);
		}
开发者ID:krabishe,项目名称:GIF89a.Transformation,代码行数:25,代码来源:DefaultQuantizer.cs


示例5: QuantizePixel

        /// <summary> Override this to process the pixel in the second pass of the algorithm. </summary>
        /// <param name="pixel"> The pixel to quantize. </param>
        /// <returns> The quantized value. </returns>
        protected override byte QuantizePixel( Color32* pixel ) {
            byte paletteIndex = (byte)maxColors; // The color at [_maxColors] is set to transparent

            // Get the palette index if this non-transparent
            if( pixel->Alpha > 0 )
                paletteIndex = (byte)octree.GetPaletteIndex( pixel );

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


示例6: TextMeshRenderer

 public TextMeshRenderer(LWF lwf, TextContext context)
     : base(lwf, context)
 {
     m_mesh = new Mesh();
     m_matrix = new Matrix4x4();
     m_renderMatrix = new Matrix4x4();
     m_colorMult = new UnityEngine.Color();
     m_colorAdd = new UnityEngine.Color();
     m_color = new Color32();
 }
开发者ID:rayyee,项目名称:lwf,代码行数:10,代码来源:lwf_drawmesh_text.cs


示例7: TextMeshRenderer

 public TextMeshRenderer(LWF lwf, UnityRenderer.TextContext context)
     : base(lwf, context)
 {
     m_matrix = new Matrix(0, 0, 0, 0, 0, 0);
     m_matrixForRender = new Matrix4x4();
     m_colorMult = new UnityEngine.Color();
     m_colorAdd = new UnityEngine.Color();
     m_color = new Color32();
     m_z = -1;
 }
开发者ID:rayyee,项目名称:lwf,代码行数:10,代码来源:lwf_combinedmesh_text.cs


示例8: QuantizePixel

        /// <summary>
        /// Override this to process the pixel in the second pass of the algorithm
        /// </summary>
        /// <param name="pixel">The pixel to quantize</param>
        /// <returns>The quantized value</returns>
        protected override byte QuantizePixel( Color32* pixel )
        {
            byte	colorIndex = 0 ;
            int		colorHash = pixel->ARGB ;

            // Check if the color is in the lookup table
            if ( _colorMap.ContainsKey ( colorHash ) )
                colorIndex = (byte)_colorMap[colorHash] ;
            else
            {
                // Not found - loop through the palette and find the nearest match.
                // Firstly check the alpha value - if < 128, set the transparent color
                if ( pixel->Alpha < 128 )
                    colorIndex = 0; // color 0 is transparent for Freebox
                else
                {
                    // Not transparent...
                    int	leastDistance = int.MaxValue ;
                    int red = pixel->Red ;
                    int green = pixel->Green;
                    int blue = pixel->Blue;

                    // Loop through the freebox palette visible colors, looking for the closest color match
                    for ( int index = 1 ; index < 192 ; index++ )
                    {
                        Color	paletteColor = _colors[index];

                        int	redDistance = paletteColor.R - red ;
                        int	greenDistance = paletteColor.G - green ;
                        int	blueDistance = paletteColor.B - blue ;

                        int		distance = ( redDistance * redDistance ) +
                                           ( greenDistance * greenDistance ) +
                                           ( blueDistance * blueDistance ) ;

                        if ( distance < leastDistance )
                        {
                            colorIndex = (byte)index ;
                            leastDistance = distance ;

                            // And if it's an exact match, exit the loop
                            if ( 0 == distance )
                                break ;
                        }
                    }
                }

                // Now I have the color, pop it into the hashtable for next time
                _colorMap.Add ( colorHash , colorIndex ) ;
            }

            return colorIndex ;
        }
开发者ID:BackupTheBerlios,项目名称:freexplorer,代码行数:58,代码来源:PaletteQuantizer.cs


示例9: drawOnImage

            public override void drawOnImage(ref Image image, BoundingBox boundingBox)
            {
                BitmapDecal decal;
                if (!BitmapDecalCache.Instance.decals.TryGetValue(_url, out decal)) return;

                Image decalImage = new Image(decal.image);
                Color32 color = new Color32(_red, _green, _blue, _alpha);
                decalImage.recolor(Global.Black32, color, false, true);
                decalImage.rotateImage(_rotation);
                if (_mirror) decalImage.flipHorizontally();

                image.blendImage(decalImage, _blendMethod, _position, _alphaOption, _textureAlpha, boundingBox);
            }
开发者ID:panteras1000,项目名称:TheWriteStuff,代码行数:13,代码来源:IM_BitmapMonoDecal.cs


示例10: QuantizePixel

        /// <summary>
        /// Override this to process the pixel in the second pass of the algorithm
        /// </summary>
        /// <param name="pixel">The pixel to quantize</param>
        /// <returns>The quantized value</returns>
        protected override byte QuantizePixel(Color32 pixel)
        {
            double luminance = (pixel.Red * 0.299) + (pixel.Green * 0.587) + (pixel.Blue * 0.114);

            // Gray scale is an intensity map from black to white.
            // Compute the index to the grayscale entry that
            // approximates the luminance, and then round the index.
            // Also, constrain the index choices by the number of
            // colors to do, and then set that pixel's index to the
            // byte value.
            byte colorIndex = (byte)(luminance + 0.5);

            return colorIndex;
        }
开发者ID:yoykiee,项目名称:ShareX,代码行数:19,代码来源:GrayscaleQuantizer.cs


示例11: QuantizePixel

		/// <summary>
		/// Override this to process the pixel in the second pass of the algorithm
		/// -- overriden here to limit distance analysis to 216 web-safe colors
		/// </summary>
		/// <param name="pixel">The pixel to quantize</param>
		/// <returns>The quantized value</returns>
		protected override byte QuantizePixel ( Color32* pixel )
		{
			// indexes of the B/W and grey area of the websafe palette:
			int[] indexes = new int[] { 0x00, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1 };

			byte	colorIndex = 0 ;
			int		colorHash = pixel->ARGB ;	

			// Check if the color is in the lookup table
			if ( _colorMap.ContainsKey ( colorHash ) )
				colorIndex = (byte)_colorMap[colorHash] ;
			else
			{
				// Not found - loop through the palette and find the nearest match.
				int	leastDistance = int.MaxValue ;
				int red = pixel->Red ;
				int green = pixel->Green;
				int blue = pixel->Blue;

				// Loop through the entire palette, looking for the closest color match
				foreach ( int index in indexes )
				{
					Color	paletteColor = _colors[index];
					
					int	redDistance = paletteColor.R - red ;
					int	greenDistance = paletteColor.G - green ;
					int	blueDistance = paletteColor.B - blue ;

					int		distance = ( redDistance * redDistance ) + 
						( greenDistance * greenDistance ) + 
						( blueDistance * blueDistance ) ;

					if ( distance < leastDistance )
					{
						colorIndex = (byte)index ;
						leastDistance = distance ;

						// And if it's an exact match, exit the loop
						if ( 0 == distance )
							break ;
					}
				}

				// Now I have the color, pop it into the hashtable for next time
				_colorMap.Add ( colorHash , colorIndex ) ;
			}

			return colorIndex ;
		}
开发者ID:slgrobotics,项目名称:QuakeMap,代码行数:55,代码来源:WebsafeGrayscaleQuantizer.cs


示例12: QuantizePixel

        /// <summary>
        /// Override this to process the pixel in the second pass of the algorithm
        /// </summary>
        /// <param name="pixel">The pixel to quantize</param>
        /// <param name="destinationPixel"></param>
        /// <returns>The quantized value</returns>
        protected override void QuantizePixel(Color32* pixel, Color32* destinationPixel)
        {
            destinationPixel->Red = pixel->Red;
            destinationPixel->Green = pixel->Green;
            destinationPixel->Blue = pixel->Blue;

            if (pixel->Alpha == _alphaEmmissiveValue)
            {
                destinationPixel->Alpha = 255;
            }
            else
            {
                destinationPixel->Alpha = 0;
            }
        }
开发者ID:midspace,项目名称:SEToolbox,代码行数:21,代码来源:EmissivePixelEffect.cs


示例13: Get

		public static Color32[] Get(byte[] table)
		{
			var result = new Color32[table.Length / 3];

			var tableIndex = 0;
			var resultIndex = 0;
			while (tableIndex < table.Length)
			{
				byte r = table[tableIndex++];
				byte g = table[tableIndex++];
				byte b = table[tableIndex++];

				result[resultIndex++] = new Color32(r, g, b);
			}

			return result;
		}
开发者ID:krabishe,项目名称:GIF89a.Transformation,代码行数:17,代码来源:Palette.cs


示例14: TestConstruction

        public void TestConstruction()
        {
            // Verify construction from an int.
            Color32 color = new Color32(OpaqueBlack);
            Assert.That(color.Abgr, Is.EqualTo(OpaqueBlack));

            // Verify construction from a bunch of RGBA bytes.
            color = new Color32(0xff, 0x00, 0x00, 0xff);
            Assert.That(color.Abgr, Is.EqualTo(OpaqueRed));

            // Verify Clone
            Color32 other = new Color32(OpaqueBlue);
            color = other.Clone();
            Assert.That(color.Abgr, Is.EqualTo(OpaqueBlue));

            // Verify parse from a string using mixed case.
            color = Color32.Parse("ff0000FF");
            Assert.That(color.Abgr, Is.EqualTo(OpaqueRed));

            // Verify correct behaviour with poorly formed string data.
            //
            // Any string supplied that is less than 8 chars is filled from the front
            // with zeros (and will thus be completely transparent).

            // An fully empty string initalizes to all zeroes (transparent black).
            color = Color32.Parse(string.Empty);
            Assert.That(color.ToString(), Is.EqualTo("00000000"));

            color = Color32.Parse("ffffff");
            Assert.That(color.ToString(), Is.EqualTo("00ffffff"));

            color = Color32.Parse("ff");
            Assert.That(color.ToString(), Is.EqualTo("000000ff"));

            // Only the first eight chars are used for construction from string. Extra
            // chars at the end of the input string are ignored.
            color = Color32.Parse("aabbccddee");
            Assert.That(color.ToString(), Is.EqualTo("aabbccdd"));

            // The input string here has two valid hex values in the first eight chars.
            // ( the "a" and "c" in "Not a c") and those are the only chars that
            // won't be replaced with zeroes.
            color = Color32.Parse("Not a color value");
            Assert.That(color.ToString(), Is.EqualTo("0000a0c0"));
        }
开发者ID:karun10,项目名称:KML2SQL,代码行数:45,代码来源:Color32Test.cs


示例15: TestGetSet

        public void TestGetSet()
        {
            // Verify getters of default state.
            Color32 color = new Color32();
            byte value = 0x00;
            Assert.That(color.Alpha, Is.EqualTo(value));
            Assert.That(color.Blue, Is.EqualTo(value));
            Assert.That(color.Green, Is.EqualTo(value));
            Assert.That(color.Red, Is.EqualTo(value));

            // Verify getters of newly set state.
            value = 0xAB;
            color = new Color32(value, value, value, value);
            Assert.That(color.Alpha, Is.EqualTo(value));
            Assert.That(color.Blue, Is.EqualTo(value));
            Assert.That(color.Green, Is.EqualTo(value));
            Assert.That(color.Red, Is.EqualTo(value));

            // Verify ABGR and ARGB.
            color = new Color32(OpaqueRed);
            Assert.That(color.Abgr, Is.EqualTo(OpaqueRed));
            Assert.That(color.Argb, Is.EqualTo(OpaqueBlue)); // Red and blue have switched?
        }
开发者ID:karun10,项目名称:KML2SQL,代码行数:23,代码来源:Color32Test.cs


示例16: ApplyShadowZeroAlloc

        protected void ApplyShadowZeroAlloc(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
        {
            UIVertex vt;

            var neededCpacity = verts.Count * 2;
            if (verts.Capacity < neededCpacity)
                verts.Capacity = neededCpacity;

            for (int i = start; i < end; ++i)
            {
                vt = verts[i];
                verts.Add(vt);

                Vector3 v = vt.position;
                v.x += x;
                v.y += y;
                vt.position = v;
                var newColor = color;
                if (m_UseGraphicAlpha)
                    newColor.a = (byte)((newColor.a * verts[i].color.a) / 255);
                vt.color = newColor;
                verts[i] = vt;
            }
        }
开发者ID:gdzzzyyy,项目名称:UGUIlok,代码行数:24,代码来源:Shadow.cs


示例17: GetPaletteIndex

                /// <summary>
                /// Return the palette index for the passed color
                /// </summary>
                public int GetPaletteIndex(Color32 pixel, int level)
                {
                    int paletteIndex = _paletteIndex;

                    if (!_leaf)
                    {
                        int shift = 7 - level;
                        int index = ((pixel.Red & mask[level]) >> (shift - 2)) |
                                    ((pixel.Green & mask[level]) >> (shift - 1)) |
                                    ((pixel.Blue & mask[level]) >> (shift));

                        if (null != _children[index])
                            paletteIndex = _children[index].GetPaletteIndex(pixel, level + 1);
                        else
                            throw new Exception("Didn't expect this!");
                    }

                    return paletteIndex;
                }
开发者ID:kooboo-jifeng,项目名称:CMS,代码行数:22,代码来源:ImageTools.cs


示例18: AddColor

                /// <summary>
                /// Add a color into the tree
                /// </summary>
                /// <param name="pixel">The color</param>
                /// <param name="colorBits">The number of significant color bits</param>
                /// <param name="level">The level in the tree</param>
                /// <param name="octree">The tree to which this node belongs</param>
                public void AddColor(Color32 pixel, int colorBits, int level, Octree octree)
                {
                    // Update the color information if this is a leaf
                    if (_leaf)
                    {
                        Increment(pixel);
                        // Setup the previous node
                        octree.TrackPrevious(this);
                    }
                    else
                    {
                        // Go to the next level down in the tree
                        int shift = 7 - level;
                        int index = ((pixel.Red & mask[level]) >> (shift - 2)) |
                                    ((pixel.Green & mask[level]) >> (shift - 1)) |
                                    ((pixel.Blue & mask[level]) >> (shift));

                        OctreeNode child = _children[index];

                        if (null == child)
                        {
                            // Create a new child node & store in the array
                            child = new OctreeNode(level + 1, colorBits, octree);
                            _children[index] = child;
                        }

                        // Add the color to the child node
                        child.AddColor(pixel, colorBits, level + 1, octree);
                    }
                }
开发者ID:kooboo-jifeng,项目名称:CMS,代码行数:37,代码来源:ImageTools.cs


示例19: InitialQuantizePixel

 /// <summary>
 /// Process the pixel in the first pass of the algorithm
 /// </summary>
 /// <param name="pixel">The pixel to quantize</param>
 /// <remarks>
 /// This function need only be overridden if your quantize algorithm needs two passes,
 /// such as an Octree quantizer.
 /// </remarks>
 protected override void InitialQuantizePixel(Color32 pixel)
 {
     // Add the color to the octree
     _octree.AddColor(pixel);
 }
开发者ID:kooboo-jifeng,项目名称:CMS,代码行数:13,代码来源:ImageTools.cs


示例20: QuantizePixel

        /// <summary>
        /// Override this to process the pixel in the second pass of the algorithm
        /// </summary>
        /// <param name="pixel">The pixel to quantize</param>
        /// <returns>The quantized value</returns>
        protected override byte QuantizePixel( Color32 pixel )
        {
            byte	colorIndex = 0 ;
            int		colorHash = pixel.ARGB ;

            // Check if the color is in the lookup table
            if ( _colorMap.ContainsKey ( colorHash ) )
                colorIndex = (byte)_colorMap[colorHash] ;
            else
            {
                // Not found - loop through the palette and find the nearest match.
                // Firstly check the alpha value - if 0, lookup the transparent color
                if ( 0 == pixel.Alpha )
                {
                    // Transparent. Lookup the first color with an alpha value of 0
                    for ( int index = 0 ; index < _colors.Length ; index++ )
                    {
                        if ( 0 == _colors[index].A )
                        {
                            colorIndex = (byte)index ;
                            break ;
                        }
                    }
                }
                else
                {
                    // Not transparent...
                    int	leastDistance = int.MaxValue ;
                    int red = pixel.Red ;
                    int green = pixel.Green;
                    int blue = pixel.Blue;

                    // Loop through the entire palette, looking for the closest color match
                    for ( int index = 0 ; index < _colors.Length ; index++ )
                    {
                        Color	paletteColor = _colors[index];

                        int	redDistance = paletteColor.R - red ;
                        int	greenDistance = paletteColor.G - green ;
                        int	blueDistance = paletteColor.B - blue ;

                        int		distance = ( redDistance * redDistance ) +
                                           ( greenDistance * greenDistance ) +
                                           ( blueDistance * blueDistance ) ;

                        if ( distance < leastDistance )
                        {
                            colorIndex = (byte)index ;
                            leastDistance = distance ;

                            // And if it's an exact match, exit the loop
                            if ( 0 == distance )
                                break ;
                        }
                    }
                }

                // Now I have the color, pop it into the hashtable for next time
                _colorMap.Add ( colorHash , colorIndex ) ;
            }

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Color4类代码示例发布时间:2022-05-24
下一篇:
C# Color类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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