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


C# Color32类代码示例

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


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


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