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