这是我的第一个基于图形的项目,首先我需要能够在具有透明度和文本的位图上绘制矩形.
我不知道从哪里开始.我做了一些研究,但似乎找不到一篇允许我为图像添加半透明矩形的文章.
我将拥有一个我需要能够操作的图像流.
有人可以指出我正确的方向吗?
有源的网站会很棒,因为我之前从未做过任何GDI工作.
小智 33
你可以尝试这样的事情:
// 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 );
Run Code Online (Sandbox Code Playgroud)
编辑:创建半透明灰色画笔的代码
Color customColor = Color.FromArgb(50, Color.Gray);
SolidBrush shadowBrush = new SolidBrush(customColor);
g.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});
Run Code Online (Sandbox Code Playgroud)
要开始,您需要从要修改的映像创建Graphics上下文.看这里.
// Create image.
Image imageFile = Image.FromFile("SampImag.bmp");
// Create graphics object for alteration.
Graphics newGraphics = Graphics.FromImage(imageFile);
Run Code Online (Sandbox Code Playgroud)
拥有Graphics对象后,您可以使用其许多方法绘制到图像上.在您的示例中,您将使用具有ARGB颜色的DrawRectangle方法在图像上创建半透明矩形.
然后,您可以将图像显示到屏幕控制或将其保存到磁盘.
| 归档时间: |
|
| 查看次数: |
29291 次 |
| 最近记录: |