gpt4 book ai didi

c# - 如何在图像上引入叠加层

转载 作者:太空狗 更新时间:2023-10-30 01:25:02 27 4
gpt4 key购买 nike

我如何操作图像以添加半透明的 1x1 选中叠加层,就像 C# 中的第二个图像一样?

enter image description here enter image description here

最佳答案

我能够修改我刚才发布的答案并在代码中创建叠加层。创建叠加图像后,我使用 TextureBrush 填充原始图像的区域。下面代码中的设置创建了以下图像;您可以根据需要更改尺寸和颜色。

enter image description here enter image description here

// set the light and dark overlay colors
Color c1 = Color.FromArgb(80, Color.Silver);
Color c2 = Color.FromArgb(80, Color.DarkGray);

// set up the tile size - this will be 8x8 pixels, with each light/dark square being 4x4 pixels
int length = 8;
int halfLength = length / 2;

using (Bitmap overlay = new Bitmap(length, length, PixelFormat.Format32bppArgb))
{
// draw the overlay - this will be a 2 x 2 grid of squares,
// alternating between colors c1 and c2
for (int x = 0; x < length; x++)
{
for (int y = 0; y < length; y++)
{
if ((x < halfLength && y < halfLength) || (x >= halfLength && y >= halfLength))
overlay.SetPixel(x, y, c1);
else
overlay.SetPixel(x, y, c2);
}
}

// open the source image
using (Image image = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\homers_brain.jpg"))
using (Graphics graphics = Graphics.FromImage(image))
{
// create a brush from the overlay image, draw over the source image and save to a new image
using (Brush overlayBrush = new TextureBrush(overlay))
{
graphics.FillRectangle(overlayBrush, new Rectangle(new Point(0, 0), image.Size));
image.Save(@"C:\Users\Public\Pictures\Sample Pictures\homers_brain_overlay.jpg");
}
}
}

关于c# - 如何在图像上引入叠加层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7898433/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com