颜色绘制在PictureBox? [英] Drawing Colors in a picturebox?
问题描述
在C#中,我有一个图片。我想提请4种颜色。默认将白,红,绿,蓝。我如何得出这个picbox stritched这4种颜色?或者我应该有4个picbox?在这种情况下如何设置RGB颜色?
In C# i have a picturebox. i would like to draw 4 colors. The default will be white, red, green, blue. How do i draw these 4 colors stritched in this picbox? or should i have 4 picbox? in that case how do i set the rgb color?
推荐答案
您需要指定它是什么,你会特别喜欢画画。你不能画一个红色的 - 这是没有意义的。你可以,但是,战平位置(0,0)一个红色矩形为100像素高,100宽。我会回答,这只是我所能,
You need to specify what it is you would specifically like to draw. You can't draw a red - that makes no sense. You can, however, draw a red rectangle at location (0,0) which is 100 pixels tall and 100 wide. I will answer what I can, however.
如果你想要的形状的轮廓设置为特定的颜色,你可以创建一个的Pen 对象。如果你想填充形状与颜色,但是,那么你可以使用一个Brush对象。下面是你如何画用红色填充的矩形的例子,一个矩形绿色概述:
If you want to set the outline of a shape to a specific color, you would create a Pen object. If you want to fill a shape with a color, however, then you would use a Brush object. Here's an example of how you would draw a rectangle filled with red, and a rectangle outlined in green:
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Brush brush = new SolidBrush(Color.Red);
graphics.FillRectangle(brush, new Rectangle(10, 10, 100, 100));
Pen pen = new Pen(Color.Green);
graphics.DrawRectangle(pen, new Rectangle(5, 5, 100, 100));
}
这篇关于颜色绘制在PictureBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!