gpt4 book ai didi

C#给图片添加图层

转载 作者:太空狗 更新时间:2023-10-29 21:37:18 24 4
gpt4 key购买 nike

我想在带有公司 Logo 的图像上添加一个图层。

Logo 应位于图像的中心(不透明)。

我该怎么做?

最佳答案

这是我之前制作的一个,它为一些图像创建了一个新徽章:

编辑,我设计了提供 maxWidth 和 maxHeight 的函数,它可以在不失真的情况下调整大小。

要求:

using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

代码

    using (Image i = Image.FromFile(HttpContext.Current.Server.MapPath(fileName)))
{
float imageWidth = i.PhysicalDimension.Width;
float imageHeight = i.PhysicalDimension.Height;
float percentage = maxWidth / imageWidth;
float newWidth = imageWidth * percentage;
float newHeight = imageHeight * percentage;

if (newHeight > maxHeight)
{
percentage = maxHeight / newHeight;

newWidth = newWidth * percentage;
newHeight = newHeight * percentage;
}

using (Bitmap b = new Bitmap((int)newWidth, (int)newHeight))
{
using (Graphics g = Graphics.FromImage(b))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

g.DrawImage(i, new Rectangle(0, 0, b.Width, b.Height));

if (effect == "new")
{
using (Image j = Image.FromFile(HttpContext.Current.Server.MapPath("/ImageEffects/") + "new.png", true))
{
g.DrawImage(j, new Rectangle(0, 0, 60, 60));

}
}

Image newImage = Image.FromHbitmap(b.GetHbitmap());

return newImage;
}
}

}
}

关于C#给图片添加图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/637801/

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