根据C#中的注册将像素放在区域中

put pixel in area according the registration in C#

我需要创建一个图形(正方形),对于在系统中注册的每个客户,我都会在客户选择的正方形位置放置一个像素。我有这个例子。我需要 C# 中关于如何获取的提示 started.This 只是一个开始的例子。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RandomPixelImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            int width = 640, height = 320;
            //bitmap
            Bitmap bmp = new Bitmap(width, height);
            //random number
            Random rand = new Random();
            //create random pixels
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    //generate random ARGB value
                    int a = rand.Next(256);
                    int r = rand.Next(256);
                    int g = rand.Next(256);
                    int b = rand.Next(256);
                    //set ARGB value
                    bmp.SetPixel(x, y, Color.FromArgb(a, r, g, b));
                }
            }
            //load bmp in picturebox1
            pictureBox1.Image = bmp;
            //save (write) random pixel image
            bmp.Save("D:\Image\RandomImage.png");
        }
    }
}

既然你已经制作了一个位图,你需要做的就是将它分配给 PictureBox 控件:

首先将一个 PictureBox 控件添加到您的窗体,然后添加此代码以将您的图像放到它上面。

pictureBox.Image = bmp;

如您的示例所示,您可以使用 Bitmap.SetPixel() 来改变单个像素。