Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在具有透明度和文本的图像上绘制矩形_C#_Gdi+ - Fatal编程技术网

C# 如何在具有透明度和文本的图像上绘制矩形

C# 如何在具有透明度和文本的图像上绘制矩形,c#,gdi+,C#,Gdi+,这是我的第一个基于图形的项目,首先,我需要能够在位图上绘制一个具有透明度和文本的矩形 我不知道从哪里开始。我做了一些研究,但似乎找不到一篇文章可以让我在图像中添加半透明矩形 我将有一个图像流,我需要能够操纵 有人能为我指出正确的方向吗 有源代码的站点会很棒,因为我以前从未做过任何GDI工作。您可以尝试以下方法: // Load the image (probably from your stream) Image image = Image.FromFile( imagePath ); usi

这是我的第一个基于图形的项目,首先,我需要能够在位图上绘制一个具有透明度和文本的矩形

我不知道从哪里开始。我做了一些研究,但似乎找不到一篇文章可以让我在图像中添加半透明矩形

我将有一个图像流,我需要能够操纵

有人能为我指出正确的方向吗


有源代码的站点会很棒,因为我以前从未做过任何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});

要开始,您需要从要修改的图像创建图形上下文

一旦你有了图形对象,你可以使用它的许多方法来绘制图像。在您的示例中,您将使用带有ARGB颜色的方法在图像上创建半透明矩形

然后,您可以将图像显示到屏幕控件或将其保存到磁盘

// Create image.
Image imageFile = Image.FromFile("SampImag.bmp");

// Create graphics object for alteration.
Graphics newGraphics = Graphics.FromImage(imageFile);