在运行时创建位图 (Visual C#)
此示例创建并填充 Bitmap 对象,然后在现有的 Windows 窗体 PictureBox 控件中显示该对象。
示例
void CreateBitmap()
{
System.Drawing.Bitmap flag = new System.Drawing.Bitmap(10, 10);
for( int x = 0; x < flag.Height; ++x )
for( int y = 0; y < flag.Width; ++y )
flag.SetPixel(x, y, Color.White);
for( int x = 0; x < flag.Height; ++x )
flag.SetPixel(x, x, Color.Red);
pictureBox1.Image = flag;
}
编译代码
本示例需要:
- 对 System 命名空间的引用。

浙公网安备 33010602011771号