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


C# Color.GetLength方法代码示例

本文整理汇总了C#中Color.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Color.GetLength方法的具体用法?C# Color.GetLength怎么用?C# Color.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Color的用法示例。


在下文中一共展示了Color.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Erosion

    /// <summary>
    /// Erode an image using a k by k box kernel
    /// </summary>
    /// <param name="i">input image</param>
    /// <param name="k">kernel thickness</param>
    /// <returns>modified image</returns>
    public Color[,] Erosion(Color[,] i, int k)
    {
        //set source image to grayscale
        i = PointProcessing.Instance.Treshold(i, 0.5f);

        Color[,] result = new Color[i.GetLength(0), i.GetLength(1)];

        for (int w = 0 + k; w < i.GetLength(0) - k; w++)
        {
            for (int h = 0 + k; h < i.GetLength(1) - k; h++)
            {
                float sum = 0f;
                for (int j = -k / 2; j <= +k / 2; j++)
                {
                    for (int l = -k / 2; l <= +k / 2; l++)
                    {
                        sum += i[w + j, h + l].r;
                    }
                }

                float res = sum < k*k ? 0f : 1f;
                result[w, h].r = res;
                result[w, h].g = res;
                result[w, h].b = res;
            }
        }
        return result;
    }
开发者ID:zilen89,项目名称:IP,代码行数:34,代码来源:Lecture03.cs

示例2: Encode

        /// <summary>
        /// Encodes the specified image data to png.
        /// </summary>
        /// <param name="pixels">
        /// The pixel data (bottom line first).
        /// </param>
        /// <param name="dpi">
        /// The image resolution in dots per inch.
        /// </param>
        /// <returns>
        /// The png image data.
        /// </returns>
        public static byte[] Encode(Color[,] pixels, int dpi = 96)
        {
            int height = pixels.GetLength(0);
            int width = pixels.GetLength(1);
            var bytes = new byte[(width * height * 4) + height];

            int k = 0;
            for (int i = height - 1; i >= 0; i--)
            {
                bytes[k++] = 0; // Filter
                for (int j = 0; j < width; j++)
                {
                    bytes[k++] = pixels[i, j].R;
                    bytes[k++] = pixels[i, j].G;
                    bytes[k++] = pixels[i, j].B;
                    bytes[k++] = pixels[i, j].A;
                }
            }

            var w = new MemoryWriter();
            w.Write((byte)0x89);
            w.Write("PNG\r\n\x1a\n".ToCharArray());
            WriteChunk(w, "IHDR", CreateHeaderData(width, height));
            WriteChunk(w, "pHYs", CreatePhysicalDimensionsData(dpi, dpi));
            WriteChunk(w, "IDAT", CreateUncompressedBlocks(bytes));
            WriteChunk(w, "IEND", new byte[0]);
            return w.ToArray();
        }
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:40,代码来源:PngEncoder.cs

示例3: DisplayArray

 static void DisplayArray(Color[,] array)
 {
     //Visit each item
     for (int row = 0; row < array.GetLength(0); row++)
         for (int col = 0; col < array.GetLength(1); col++)
             canvas.SetBBScaledPixel(col, row, array[row, col]);
 }
开发者ID:NAIT-CNT,项目名称:CMPE1300.Public,代码行数:7,代码来源:Program.cs

示例4: RenderEffect

        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight);
            var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth);
            var random = new Random(chkBoxStrobe.Checked ? DateTime.Now.Millisecond : 2271965);
            var steps = tbSteps.Value;
            var stepsHalf = steps / 2.0f;
            var lights = Convert.ToInt32((bufferHeight * bufferWidth) * (tbLightCount.Value / 100.0));
            var step = Math.Max(1, (bufferHeight * bufferWidth) / lights);

            for (var y = 0; y < bufferHeight; y++) {
                for (var x = 0; x < bufferWidth; x++) {
                    if ((y * bufferHeight + x + 1) % step != 1 && step != 1) {
                        continue;
                    }

                    var hsv = palette[random.Next() % palette.Length].ToHSV();

                    var randomStep = (eventToRender + random.Next()) % steps;

                    hsv.Value = chkBoxStrobe.Checked ? ((randomStep == (int)(stepsHalf + 0.5f)) ? 1.0f : 0.0f) :
                        Math.Max(0.0f, ((randomStep <= stepsHalf ? randomStep : steps - randomStep) / stepsHalf));

                    buffer[y, x] = hsv.ToColor();
                }
            }
            return buffer;
        }
开发者ID:jmcadams,项目名称:vplus,代码行数:28,代码来源:Twinkle.cs

示例5: RenderEffect

        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            _palette = palette;
            _bufferHeight = buffer.GetLength(0);
            _bufferWidth = buffer.GetLength(1);

            if (eventToRender == 0 || _tempBuf == null) {
                InitializeSnowflakes();
            }

            // move snowflakes
            for (var x = 0; x < _bufferWidth; x++) {
                var newX = (x + eventToRender / 20) % _bufferWidth; // CW
                var newX2 = (x - eventToRender / 20) % _bufferWidth; // CCW
                if (newX2 < 0) {
                    newX2 += _bufferWidth;
                }
                for (var y = 0; y < _bufferHeight; y++) {
                    var newY = (y + eventToRender / 10) % _bufferHeight;
                    var newY2 = (newY + _bufferHeight / 2) % _bufferHeight;
                    var color1 = GetTempPixel(newX, newY);
                    if (color1 == Color.Transparent) {
                        color1 = GetTempPixel(newX2, newY2);
                    }
                    buffer[y,x] = color1;
                }
            }
            return buffer;
        }
开发者ID:jmcadams,项目名称:vplus,代码行数:29,代码来源:Snowflakes.cs

示例6: CreateSprite

	public override Texture2D CreateSprite (Texture2D texture)
	{
		Color[] pixels = texture.GetPixels ();
		Color[,] pixels2D = new Color[texture.width, texture.height];
		for (int i = 0; i < pixels.Length; i++) {
			
			int x = i % texture.width;
			int y = i / texture.height;

			pixels2D [x, y] = pixels [i];
		}

		int amountOfEyes = (int)(sightAngle / 45);
		for (int i = 0; i < amountOfEyes; i++) {
			
			int radius = (texture.width - eyeSize) / 2;
			float xPos = Mathf.Sin (Mathf.Deg2Rad * (i * 45));
			float yPos = Mathf.Cos (Mathf.Deg2Rad * (i * 45));
			Vector2 pos = new Vector2 (xPos, yPos) * radius + new Vector2 (texture.width - eyeSize, texture.height - eyeSize) / 2;

			ApplyKernel (ref pixels2D, texture.width, texture.height, pos);
		}

		for (int x = 0; x < pixels2D.GetLength (0); x++) {
			for (int y = 0; y < pixels2D.GetLength (1); y++) {
				
				pixels [x + y * texture.width] = pixels2D [x, y];
			}
		}

		texture.SetPixels (pixels);
		texture.Apply ();

		return texture;
	}
开发者ID:MrImitate,项目名称:Procedural-Gen,代码行数:35,代码来源:Part_Eye.cs

示例7: TexturesCollide

 public static bool TexturesCollide(Color[,] tex1, Matrix mat1, Color[,] tex2, Matrix mat2)
 {
     int width1 = tex1.GetLength(0);
     int height1 = tex1.GetLength(1);
     int width2 = tex2.GetLength(0);
     int height2 = tex2.GetLength(1);
     Matrix mat1to2 = mat1 * Matrix.Invert(mat2);
     for (int x1 = 0; x1 < width1; x1++)
     {
         for (int y1 = 0; y1 < height1; y1++)
         {
             Vector2 pos1 = new Vector2(x1, y1);
             Vector2 pos2 = Vector2.Transform(pos1, mat1to2);
             int x2 = (int)pos2.X;
             int y2 = (int)pos2.Y;
             if ((x2 < 0) || (x2 >= width2)) continue;
             if ((y2 < 0) || (y2 >= height2)) continue;
             if (tex1[x1, y1].A <= 0)
             {
                 var tmp = 1 + 1;
                 var other = tmp + 1;
                 continue;
             }
             if (tex2[x2, y2].A <= 0) continue;
     //                    Vector2 screenPos = Vector2.Transform(pos1, mat1);
     //                    return screenPos;
             return true;
         }
     }
     //            return new Vector2(-1, -1);
     return false;
 }
开发者ID:Thecontrarian,项目名称:XnaUtility,代码行数:32,代码来源:UtilityMethods.cs

示例8: apply

        public override Color[,] apply(Color[,] imageToProcess, MainViewModel reportProgressTo)
        {
            imageToProcess = base.apply(imageToProcess, reportProgressTo);

            for (int i = 0; i < imageToProcess.GetLength(0); i++)
            {
                int firstPixelY = -1;
                for (int j = 0; j < imageToProcess.GetLength(1); j++)
                {
                    if (imageToProcess[i, j].ToArgb() == Color.Black.ToArgb())
                        if (firstPixelY <= 0 || firstPixelY + 1 == j)
                            firstPixelY = j;
                        else
                        {
                            for (int k = firstPixelY + 1; k < j; k++)
                                imageToProcess[i, k] = Color.Black;

                            firstPixelY = -1;
                        }

                    reportProgressTo.Progress++;
                }
            }

            return imageToProcess;
        }
开发者ID:aelex13,项目名称:RugbyIBV,代码行数:26,代码来源:FillObjectFilter.cs

示例9: RenderEffect

        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            const int speedFactor = 200;
            var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight);
            var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth);

            Color color;
            var hsv2 = new HSV();
            var colorcnt = palette.Length;
            var cycleLen = colorcnt * speedFactor;
            var count = tbCount.Value;
            if (eventToRender > (colorcnt - 1) * speedFactor * count && count < 10) {
                color = palette.GetMultiColorBlend(count % 2, false);
            } else {
                color = palette.GetMultiColorBlend(eventToRender % cycleLen / (double)cycleLen, true);
            }
            var hsv = color.ToHSV();
            var halfHeight = (bufferHeight - 1) / 2.0;
            var halfWidth = (bufferWidth - 1) / 2.0;
            for (var col = 0; col < bufferWidth; col++) {
                for (var row = 0; row < bufferHeight; row++) {
                    hsv2.SetToHSV(hsv);
                    if (chkBoxHFade.Checked) hsv2.Value *= (float)(1.0 - Math.Abs(halfWidth - col) / halfWidth);
                    if (chkBoxVFade.Checked) hsv2.Value *= (float)(1.0 - Math.Abs(halfHeight - row) / halfHeight);
                    buffer[row, col] = hsv2.ToColor();
                }
            }
            return buffer;
        }
开发者ID:jmcadams,项目名称:vplus,代码行数:29,代码来源:ColorWash.cs

示例10: RenderEffect

        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            var colorCount = palette.Length;
            var spiralCount = colorCount * tbPaletteRepeat.Value;
            var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight);
            var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth);
            var deltaStrands = bufferWidth / spiralCount;
            var spiralThickness = (deltaStrands * tbThickness.Value / 100) + 1;
            long spiralState = eventToRender * tbDirection.Value;

            for (var spiral = 0; spiral < spiralCount; spiral++) {
                var strandBase = spiral * deltaStrands;
                var color = palette[spiral % colorCount];
                for (var thickness = 0; thickness < spiralThickness; thickness++) {
                    var strand = (strandBase + thickness) % bufferWidth;
                    for (var row = 0; row < bufferHeight; row++) {
                        var column = (strand + ((int)spiralState / 10) + (row * tbRotations.Value / bufferHeight)) % bufferWidth;
                        if (column < 0) {
                            column += bufferWidth;
                        }
                        if (chkBoxBlend.Checked) {
                            color = palette.GetMultiColorBlend((bufferHeight - row - 1) / (double)bufferHeight, false);
                        }
                        if (chkBox3D.Checked) {
                            var hsv = color.ToHSV();
                            hsv.Value = (float)((double)(tbRotations.Value < 0 ? thickness + 1 : spiralThickness - thickness) / spiralThickness);
                            color = hsv.ToColor();
                        }
                        buffer[row, column] = color;
                    }
                }
            }
            return buffer;
        }
开发者ID:jmcadams,项目名称:vplus,代码行数:34,代码来源:Spirals.cs

示例11: Create

        public Bitmap Create(Color[,] data)
        {
            int width = data.GetLength(0);
            int height = data.GetLength(1);

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            BitmapData bmData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);

            int stride = bmData.Stride;

            byte[] array = new byte[stride * height];

            int index = 0;

            for (int y = height - 1; y >= 0; y--)
            {
                for (int x = 0; x < width; x++)
                {
                    array[index++] = data[x, y].B;
                    array[index++] = data[x, y].G;
                    array[index++] = data[x, y].R;
                }
            }

            IntPtr scan0 = bmData.Scan0;
            Marshal.Copy(array, 0, scan0, stride * bitmap.Height);
            bitmap.UnlockBits(bmData);

            return bitmap;
        }
开发者ID:anfulu36484,项目名称:GravitatioanlSimulation,代码行数:30,代码来源:FastBitmapCreator.cs

示例12: TexturesCollide

        public static Boolean TexturesCollide(Color[,] texture1, Matrix matrix1, Color[,] texture2, Matrix matrix2)
        {
            Matrix mat1to2 = matrix1 * Matrix.Invert(matrix2);
            Int32 width1 = texture1.GetLength(0);
            Int32 height1 = texture1.GetLength(1);
            Int32 width2 = texture2.GetLength(0);
            Int32 height2 = texture2.GetLength(1);

            for (Int32 x1 = 0; x1 < width1; x1++) {
                for (Int32 y1 = 0; y1 < height1; y1++) {
                    Vector2 pos1 = new Vector2(x1, y1);
                    Vector2 pos2 = Vector2.Transform(pos1, mat1to2);

                    Int32 x2 = (Int32)pos2.X;
                    Int32 y2 = (Int32)pos2.Y;
                    if ((x2 >= 0) && (x2 < width2)) {
                        if ((y2 >= 0) && (y2 < height2)) {
                            if (texture1[x1, y1].A > 0) {
                                if (texture2[x2, y2].A > 0) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            return false;
        }
开发者ID:bstockus,项目名称:WarehouseZombieAttack,代码行数:29,代码来源:CollisionHelper.cs

示例13: RenderEffect

        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight);
            var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth);
            var colorcnt = palette.Length;

            var halfWidth = Math.Max(1, bufferWidth / 2);
            var halfHeight = Math.Max(1, bufferHeight / 2);
            var outterR = (float) (halfWidth * (tbOuterR.Value / 100.0));
            var innerR = (float) (halfWidth * (tbInnerR.Value / 100.0));
            if (innerR > outterR) innerR = outterR;
            var distance = (float) (halfWidth * (tbDistance.Value / 100.0));

            var mod1440 = eventToRender % 1440;
            var originalDistance = distance;
            for (var i = 1; i <= 360; i++) {
                if (chkBoxAnimate.Checked) distance = (int) (originalDistance + eventToRender / 2.0) % 100;
                var t = (float) ((i + mod1440) * Math.PI / 180);
                var x = Convert.ToInt32((outterR - innerR) * Math.Cos(t) + distance * Math.Cos(((outterR - innerR) / innerR) * t) + halfWidth);
                var y = Convert.ToInt32((outterR - innerR) * Math.Sin(t) + distance * Math.Sin(((outterR - innerR) / innerR) * t) + halfHeight);
                var x2 = Math.Pow((x - halfWidth), 2);
                var y2 = Math.Pow((y - halfHeight), 2);
                var hyp = (Math.Sqrt(x2 + y2) / bufferWidth) * 100.0;

                if (x >= 0 && x < bufferWidth && y >= 0 && y < bufferHeight) {
                    buffer[y, x] = palette[(int)(hyp / (colorcnt > 0 ? bufferWidth / colorcnt : 1)) % colorcnt];
                }
            }
            return buffer;
        }
开发者ID:jmcadams,项目名称:vplus,代码行数:30,代码来源:Spirograph.cs

示例14: interpolation

        public Color interpolation(Color[,] original_Buffer, PointF p)
        {
            int x1 = (int)Math.Floor(p.X),
                y1 = (int)Math.Floor(p.Y),
                x2 = x1 + 1,
                y2 = y1 + 1;

            x1 = OutBoundery(x1, original_Buffer.GetLength(0));
            x2 = OutBoundery(x2, original_Buffer.GetLength(0));
            y1 = OutBoundery(y1, original_Buffer.GetLength(1));
            y2 = OutBoundery(y2, original_Buffer.GetLength(1));

            Color p1 = original_Buffer[x1, y1];
            Color p2 = original_Buffer[x2, y1];
            Color p3 = original_Buffer[x1, y2];
            Color p4 = original_Buffer[x2, y2];

            double Xfraction = p.X - x1;
            double Yfraction = p.Y - y1;

            //interpolate in X_Direction
            Data dataX1, dataX2, dataFinal;
            dataX1 = interpolate(p1, p2, Xfraction);
            dataX2 = interpolate(p3, p4, Xfraction);
            //interpolate in Y_Direction
            Color newX1 = Color.FromArgb((int)dataX1.R_Val, (int)dataX1.G_Val, (int)dataX1.B_Val);
            Color newX2 = Color.FromArgb((int)dataX2.R_Val, (int)dataX2.G_Val, (int)dataX2.B_Val);
            dataFinal = interpolate(newX1, newX2, Yfraction);

            return Color.FromArgb((int)(dataFinal.R_Val), (int)(dataFinal.G_Val), (int)(dataFinal.B_Val));
        }
开发者ID:ahmedelkashef,项目名称:GP,代码行数:31,代码来源:GeometryOperations.cs

示例15: ConvertToGreyscale

 public static int[,] ConvertToGreyscale(Color[,] colors, decimal redWeight, decimal greenWeight, decimal blueWeight)
 {
     int[,] grey = new int[colors.GetLength(0), colors.GetLength(1)];
     for (int x = 0; x < colors.GetLength(0); x++)
         for (int y = 0; y < colors.GetLength(1); y++)
             grey[x, y] = (int)(redWeight * colors[x, y].R + greenWeight * colors[x, y].G + blueWeight * colors[x, y].B);
     return grey;
 }
开发者ID:jlvermeulen,项目名称:image-processing,代码行数:8,代码来源:Conversions.cs


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