簡體   English   中英

根據C#中的配准將像素放在區域中

[英]put pixel in area according the registration in C#

我需要創建一個數字(正方形),其中對於系統中注冊的每個客戶端,我將一個像素放置在客戶端選擇的正方形位置。 我有這個例子。 我需要C#中有關如何開始的提示。這僅是示例。

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()更改單個像素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM