如何填充用纯色的位图? [英] How do I fill a bitmap with a solid color?
本文介绍了如何填充用纯色的位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建采用了独特的RGB颜色24位位图(分辨率100×100像素),生成的图像保存到磁盘。我目前使用 的setPixel
功能,但它是非常缓慢的。
I need to create a 24-bit bitmap (resolution 100x100 pixels) using a unique RGB color and save the generated image to the disk. I currently use the SetPixel
function, but it is extremely slow.
Bitmap Bmp = new Bitmap(width, height);
//...
//...
Bmp.SetPixel(x,y,Color.FromARGB(redvalue, greenvalue, bluevalue));
难道还有比的setPixel
更快的方法?先谢谢了。
Is there a faster method than SetPixel
? Thanks in advance.
推荐答案
这应该做你需要什么。它会填满整个位图用指定的颜色。
This should do what you need it to. It will fill the entire bitmap with the specified color.
Bitmap Bmp = new Bitmap(width, height);
using (Graphics gfx = Graphics.FromImage(Bmp))
using (SolidBrush brush = new SolidBrush(Color.FromArgb(redvalue, greenvalue, bluevalue)))
{
gfx.FillRectangle(brush, 0, 0, width, height);
}
这篇关于如何填充用纯色的位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文