大家好,又见面了,我是你们的朋友全栈君。
private void pictureBox1_Click(object sender, EventArgs e)
{
Image Imageimage;
Imageimage = System.Drawing.Image.FromFile(@"D:\black.png");
Bitmap bitmap = new Bitmap(Imageimage);
bitmap.MakeTransparent(Color.White);
Imageimage = System.Drawing.Image.FromFile(@"D:\white.png");
Bitmap bitmap1 = new Bitmap(Imageimage);
bitmap1.MakeTransparent(Color.Black);
Graphics g = pictureBox1.CreateGraphics();
g.Clear(pictureBox1.BackColor);
for (int j = 0; j < 4; j++)
for (int i = 0; i < 5; i++)
{
Image x;
Random random = new Random();
int n = random.Next(1, 3);
if (n==1)
{
x = bitmap;
g.DrawImage(x, new Point(i * 100, j * 100));
}
if(n==2)
{
x = bitmap1;
g.DrawImage(x, new Point(i * 100, j * 100));
}
}
//pictureBox1.Image = bitmap;
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162719.html原文链接:https://javaforall.net