这是我的第一个基于图形的项目,首先我需要能够在带透明度和文字的位图上绘制一个矩形。
我不确定从哪里开始。我已经做了一些研究,但似乎没有找到一篇文章可以让我向图片中添加半透明的矩形。
我将拥有一个需要操纵的图像流。
请问有人可以为我指明正确的方向吗?最好是带源代码的网站,因为我以前从未进行过GDI工作。
您可以尝试类似下面的方法:
// Load the image (probably from your stream)
Image image = Image.FromFile( imagePath );
using (Graphics g = Graphics.FromImage(image))
{
// Modify the image using g here...
// Create a brush with an alpha value and use the g.FillRectangle function
}
image.Save( imageNewPath );
编辑:创建半透明灰色画笔的代码
Color customColor = Color.FromArgb(50, Color.Gray);
SolidBrush shadowBrush = new SolidBrush(customColor);
g.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});
// Create image.
Image imageFile = Image.FromFile("SampImag.bmp");
// Create graphics object for alteration.
Graphics newGraphics = Graphics.FromImage(imageFile);