【发布时间】:2016-12-22 20:03:30
【问题描述】:
在 Form1 中,我在构造函数中创建了一个新的位图:
public Form1()
{
InitializeComponent();
de.pb1 = pictureBox1;
de.bmpWithPoints = new Bitmap(pictureBox1.Width, pictureBox1.Height);
de.numberOfPoints = 100;
de.randomPointsColors = false;
de.Init();
}
在课堂上我检查位图是否为空:
if (bmpWithPoints == null)
位图不为空,但也没有绘制任何内容。 我检查类是否为空我想在位图上绘制和设置点。
if (bmpWithPoints == null)
{
for (int x = 0; x < bmpWithPoints.Width; x++)
{
for (int y = 0; y < bmpWithPoints.Height; y++)
{
bmpWithPoints.SetPixel(x, y, Color.Black);
}
}
Color c = Color.Red;
for (int x = 0; x < numberOfPoints; x++)
{
for (int y = 0; y < numberOfPoints; y++)
{
if (randomPointsColors == true)
{
c = Color.FromArgb(
r.Next(0, 256),
r.Next(0, 256),
r.Next(0, 256));
}
else
{
c = pointsColor;
}
bmpWithPoints.SetPixel(r.Next(0, bmpWithPoints.Width),
r.Next(0, bmpWithPoints.Height), c);
}
}
}
else
{
randomPointsColors = false;
}
也许问题不应该是图像是空的还是空的,我不知道如何调用它。也许只是一个新形象。但我想检查新位图是否(空)上没有绘制然后设置像素(点)。
【问题讨论】:
标签: c# .net winforms bitmap gdi+