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


C# Bitmap.SetPixel方法代码示例

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


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

示例1: Run

        public override void Run()
        {
            try
            {
                using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height))
                {
                    int size = System.Math.Min(Dimensions.Width, Dimensions.Height);

                    for (int i = 0; i < size; ++i)
                        bmp.SetPixel(i, i, (Color)((255 - i) << 16));

                    for (int i = 0; i < size; i += 2)
                        bmp.SetPixel(size - i, i, (Color)(i << 8));

                    bmp.Flush();
                }

                Thread.Sleep(3000);
                Pass = true;
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
开发者ID:dario-l,项目名称:kodfilemon.blogspot.com,代码行数:25,代码来源:GreenBlueX.cs

示例2: ChangeBitmapColor

 public static void ChangeBitmapColor(Bitmap img, Color anyDifferentColor, Color changeTo)
 {
     for (int x = 0; x < img.Width; x++)
         for (int y = 0; y < img.Height; y++)
             if (img.GetPixel(x, y) != anyDifferentColor)
                 img.SetPixel(x, y, changeTo);
 }
开发者ID:andrei-tatar,项目名称:MediaPlayer.NETMF,代码行数:7,代码来源:Utils.cs

示例3: ToBitmap

        /// <summary>
        /// Converts this ByteMatrix to a black and white bitmap.
        /// </summary>
        /// <returns>A black and white bitmap converted from this ByteMatrix.</returns>
        public Bitmap ToBitmap(BarcodeFormat format, String content)
        {
            int width = Width;
            int height = Height;
            bool outputContent = !(content == null || content.Length == 0) && (format == BarcodeFormat.CODE_39 ||
                                                                    format == BarcodeFormat.CODE_128 ||
                                                                    format == BarcodeFormat.EAN_13 ||
                                                                    format == BarcodeFormat.EAN_8 ||
                                                                    format == BarcodeFormat.CODABAR ||
                                                                    format == BarcodeFormat.ITF ||
                                                                    format == BarcodeFormat.UPC_A);
            int emptyArea = outputContent ? 16 : 0;

            // create the bitmap and lock the bits because we need the stride
            // which is the width of the image and possible padding bytes
            var bmp = new Bitmap(width, height);
            for (int y = 0; y < height - emptyArea; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var color = this[x, y] ? Color.Black : Color.White;
                    bmp.SetPixel(x, y, color);
                }
            }

            if (outputContent)
            {
                //switch (format)
                //{
                //   case BarcodeFormat.EAN_8:
                //      if (content.Length < 8)
                //         content = OneDimensionalCodeWriter.CalculateChecksumDigitModulo10(content);
                //      content = content.Insert(4, "   ");
                //      break;
                //   case BarcodeFormat.EAN_13:
                //      if (content.Length < 13)
                //         content = OneDimensionalCodeWriter.CalculateChecksumDigitModulo10(content);
                //      content = content.Insert(7, "   ");
                //      content = content.Insert(1, "   ");
                //      break;
                //}
                bmp.DrawText(content, null, Color.Black, width / 2, height - 14);
            }

            return bmp;
        }
开发者ID:cyberh0me,项目名称:OTP,代码行数:50,代码来源:BitMatrix.Drawing.cs

示例4: Run

 public override void Run()
 {
     try
     {
         using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height))
         {
             var rand = new Random();
             for (int i = 0; i < 100; i++)
             {
                 bmp.SetPixel(rand.Next(Dimensions.Width),
                              rand.Next(Dimensions.Height),
                              (Color) rand.Next(0xFFFFFF));
                 bmp.Flush();
             }
         }
         Pass = true;
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
开发者ID:dario-l,项目名称:kodfilemon.blogspot.com,代码行数:22,代码来源:RandomSetPixel.cs

示例5: Run

        public override void Run()
        {
            try
            {
                using (var scratch = new Bitmap(64, 32))
                {
                    for (int x = 0; x < scratch.Width; x++)
                    {
                        for (int y = 0; y < scratch.Height; y++)
                        {
                            Color color = ColorUtility.ColorFromRGB((byte) (x*255/scratch.Width),
                                                                    (byte) (y*255/(scratch.Height)),
                                                                    (byte) (255 - x*255/scratch.Width));
                            scratch.SetPixel(x, y, color);
                        }
                    }

                    using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height))
                    {
                        var rand = new Random();

                        for (int i = 0; i < 100; i++)
                        {
                            bmp.DrawImage(rand.Next(Dimensions.Width),
                                          rand.Next(Dimensions.Height),
                                          scratch, 0, 0,
                                          scratch.Width, scratch.Height);
                            bmp.Flush();
                        }
                    }
                }
                Pass = true;
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
开发者ID:dario-l,项目名称:kodfilemon.blogspot.com,代码行数:38,代码来源:RandomDrawImage.cs

示例6: Run

        public override void Run()
        {
            int focus = 15;
            
            using (var bmp = new Bitmap(Dimensions.Width, Dimensions.Height))
            {
                DateTime barier = DateTime.Now.AddSeconds(5);
                while(DateTime.Now < barier)
                {
                    bmp.Clear();

                    foreach (var star in _stars)
                    {
                        int x = star.X*focus/star.Z + Dimensions.Width/2;
                        int y = Dimensions.Height/2 - star.Y*focus/star.Z;

                        if (x >= 0 && y >= 0 && x <= bmp.Width && y <= bmp.Height)
                        {
                            if (star.Z > 20)
                                bmp.SetPixel(x, y, Color.White);
                            else
                            {
                                bmp.SetPixel(x, y, Color.White);
                                bmp.SetPixel(x - 1, y, Color.White);
                                bmp.SetPixel(x + 1, y, Color.White);
                                bmp.SetPixel(x, y - 1, Color.White);
                                bmp.SetPixel(x, y + 1, Color.White);
                            }
                        }

                        star.Fly();
                    }

                    bmp.Flush();
                    Thread.Sleep(5);
                }
            }
        }
开发者ID:dario-l,项目名称:kodfilemon.blogspot.com,代码行数:38,代码来源:MilkyWay.cs

示例7: FillArea

        /// <summary>
        /// This method fills an area which surrounded by line(s). Not only polygon but also circle, pentagram, cloud shaped... any figure. Only you need to fill is set Bitmap, Color, certain X and Y to argument. Both X and Y should be exist inner line(s).
        /// </summary>
        /// <param name="screen"></param>
        /// <param name="color"></param>
        public void FillArea(Bitmap screen, Color color, Point point)
        {

            int currentY = 0;
            int minY = 0;
            int maxY = 0;

            //screen.SetPixel(x, y, color);

            currentY = point.Y - 1;

            while (currentY >= 0 && screen.GetPixel(point.X, currentY) != color)
            {
                screen.SetPixel(point.X, currentY, color);
                currentY--;
            }

            minY = currentY + 1;

            currentY = point.Y;

            while (currentY < screen.Height && screen.GetPixel(point.X, currentY) != color)
            {
                screen.SetPixel(point.X, currentY, color);
                currentY++;
            }

            maxY = currentY - 1;


            for (int i = minY; i < maxY; i++)
            {

                if (point.X > 0 && screen.GetPixel(point.X - 1, i) != color)
                {
                    FillArea(screen, color, new Point(point.X - 1, i));
                }

                if (point.X < screen.Width - 1 && screen.GetPixel(point.X + 1, i) != color)
                {
                    FillArea(screen, color, new Point(point.X + 1, i));
                }

            }

        }
开发者ID:nothingmn,项目名称:WP8-Running.AGENT,代码行数:51,代码来源:Drawing.cs

示例8: DrawPoly

        /// <summary>
        /// Draws polygon from list of points and fill it with specififed pattern. 
        /// </summary>
        /// <param name="screen">Bitmap to draw on</param>
        /// <param name="points">Array of points defining polygon</param>
        /// <param name="borderColor">Color of poly border</param>
        /// <param name="borderWidth">Poly border width</param>
        /// <param name="fillColor">Color to use to fill poly</param>
        /// <param name="polyFill">Fill patern. Empty will simply draw unfilled poly</param>
        public void DrawPoly(Bitmap screen, Point[] points, Color borderColor, short borderWidth, Color fillColor, PolyFill polyFill)
        {
            if (points.Length < 3) return; // we need at least 3 point for poly

            if (borderWidth < 1)
                borderWidth = 1;

            Color fgColor, bgColor;

            if (fillColor == Color.Black)
            {
                fgColor = Color.Black;
                bgColor = Color.White;
            }
            else
            {
                fgColor = Color.White;
                bgColor = Color.Black;

            }

            if (polyFill == PolyFill.POLYFILL_EMPTY)
                _DrawUnfilledPoly(screen, points, borderColor, borderWidth, new Point(0, 0));
            else
            {
                Point br = new Point(0, 0), tl = new Point(screen.Width, screen.Height);
                // find bounding box
                for (int i = 0; i < points.Length; ++i)
                {
                    tl.X = (tl.X > points[i].X) ? points[i].X : tl.X;
                    tl.Y = (tl.Y > points[i].Y) ? points[i].Y : tl.Y;
                    br.X = (br.X < points[i].X) ? points[i].X : br.X;
                    br.Y = (br.Y < points[i].Y) ? points[i].Y : br.X;
                }

                // adjust binding box to fit thick border. Foê some reason SPOT.Bitmap double the border width (at least on emulator)
                if (borderWidth > 1)
                {
                    tl.X = (short)((tl.X > borderWidth) ? tl.X - borderWidth * 2 : 0);
                    tl.Y = (short)((tl.Y > borderWidth) ? tl.Y - borderWidth * 2 : 0);
                    br.X = (short)((br.X + borderWidth < (screen.Width - 1)) ? br.X + borderWidth * 1.5 : 0);
                    br.Y = (short)((br.Y + borderWidth < (screen.Width - 1)) ? br.Y + borderWidth * 1.5 : 0);
                }

                // we need separate bitmap to draw poly as one specififed can have some drawing already and we won't be able to detect border properly
                Bitmap buffer = new Bitmap((br.X - tl.X + 1), (br.Y - tl.Y + 1));

                // fill bitmap with color opposite to border color
                if (borderColor == Color.Black)
                    buffer.DrawRectangle(Color.White, 0, 0, 0, buffer.Width, buffer.Height, 0, 0, Color.White, 0, 0, Color.White, buffer.Width, buffer.Height, 0xFF);
                else
                    buffer.DrawRectangle(Color.Black, 0, 0, 0, buffer.Width, buffer.Height, 0, 0, Color.Black, 0, 0, Color.Black, buffer.Width, buffer.Height, 0xFF);

                _DrawUnfilledPoly(buffer, points, borderColor, borderWidth, tl);

                // scan created bitmap
                bool isInside = false, onBorder = false;
                int startX = -1, borderStart = -1;
                for (int y = 0; y < buffer.Height; ++y)
                {
                    isInside = false;
                    onBorder = false;
                    startX = -1;
                    borderStart = -1;
                    for (int x = 0; x < buffer.Width; ++x)
                    {
                        if (buffer.GetPixel(x, y) == borderColor)
                        {
                            if (onBorder)
                            {
                                // still on border
                                screen.SetPixel(x + tl.X, y + tl.Y, borderColor);
                            }
                            else
                            {
                                // we have reached border from inside/outside
                                if (isInside)
                                {
                                    //isInside = false;
                                    if (startX >= 0)
                                    {
                                        // draw pattern line
                                        for (int k = startX; k < x; ++k)
                                        {
                                            if (polyFill == PolyFill.POLYFILL_SOLID) screen.SetPixel(k + tl.X, y + tl.Y, fgColor);
                                            else if (polyFill == PolyFill.POLYFILL_HORIZONTAL)
                                                screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_horizontal[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor);
                                            else if (polyFill == PolyFill.POLYFILL_HORIZONTAL)
                                                screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_horizontal[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor);
                                            else if (polyFill == PolyFill.POLYFILL_VERTICAL)
                                                screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_vertical[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor);
//.........这里部分代码省略.........
开发者ID:nothingmn,项目名称:WP8-Running.AGENT,代码行数:101,代码来源:Drawing.cs

示例9: Run

		public override void Run()
		{
			try
			{
				Bitmap scratch = new Bitmap( 64, 32 );

				for(int x = 0; x < scratch.Width; x++)
				{
					for(int y = 0; y < scratch.Height; y++)
					{
						scratch.SetPixel( x, y, Utility.FromRGB( x * 255 / (scratch.Width), y * 255 / (scratch.Height), 255 - x * 255 / (scratch.Width) ) );
					}
				}

				Bitmap bmp = new Bitmap( Dimensions.Width, Dimensions.Height );
                Random rand = new Random();

				for(int i = 0; i < 1000; i++)
				{
					bmp.DrawImage( rand.Next( Dimensions.Width ), rand.Next( Dimensions.Height ), scratch, 0, 0, scratch.Width, scratch.Height );
					bmp.Flush();
				}
				Pass = true;
			}
			catch(Exception e)
			{
				UnexpectedException( e );
			}
		}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:29,代码来源:Main.cs

示例10: DrawLine

 public static void DrawLine(int x1, int y1, int x2, int y2, bool color, Bitmap bmp)
 {
     int x_s, x_e;
     float slope;
     bool useX;
     if (x1 == x2)
     {
         if (y1 == y2)
         {
             DrawPoint(x1, y1, color);
             return;
         }
         useX = false;
         slope = (float)(x2 - x1) / (y2 - y1);
     }
     else
     {
         slope = (float)(y2 - y1) / (x2 - x1);
         useX = System.Math.Abs(slope) < 1.0f;
         if (!useX) slope = 1.0f / slope;
     }
     float y;
     if (useX) //X is primary
     {
         if (x1 < x2)
         {
             x_s = x1;
             x_e = x2;
             y = y1 + 0.5f;
         }
         else
         {
             x_s = x2;
             x_e = x1;
             y = y2 + 0.5f;
         }
         for (int x = x_s; x < x_e; x++)
         {
             //DrawPoint(x, (int)y, color);
             bmp.SetPixel(x, (int)y, color ? Color.Black : Color.White);
             y += slope;
         }
     }
     else //Y is primary
     {
         //slope = 1 / slope;
         if (y1 < y2)
         {
             x_s = y1;
             x_e = y2;
             y = x1 + 0.5f;
         }
         else
         {
             x_s = y2;
             x_e = y1;
             y = x2 + 0.5f;
         }
         for (int x = x_s; x < x_e; x++)
         {
             DrawPoint((int)y, x, color);
             y += slope;
         }
     }
 }
开发者ID:LONELY-WOLF,项目名称:TriDi,代码行数:65,代码来源:Display.cs


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