谢谢你,德文!这是我的 C# 代码,用于实现您的建议。它工作得很好。将其变成社区拥有的 Wiki 帖子,如果有人喜欢添加一些代码,请随时编辑。
(示例使用的 Alpha 和曝光值与下面的代码不同)
Image img = Image.FromFile("rss-icon.jpg");
pictureBox1.Image = AddCircularGloss(img, 30,25,255,255,255);
public static Image AddCircularGloss(Image inputImage, int exposurePercentage, int transparency, int fillColorR, int fillColorG, int fillColorB)
{
Bitmap outputImage = new Bitmap(inputImage);
using (Graphics g = Graphics.FromImage(outputImage))
{
using (Pen p = new Pen(Color.FromArgb(transparency, fillColorR, fillColorG, fillColorB)))
{
// Looks jaggy otherwise
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
int x, y;
// 3 * Height looks best
int diameter = outputImage.Height * 3;
double imgPercent = (double)outputImage.Height / 100;
x = 0 - outputImage.Width;
// How many percent of the image to expose
y = (0 - diameter) + (int)(imgPercent * exposurePercentage);
g.FillEllipse(p.Brush, x, y, diameter, diameter);
}
}
return outputImage;
}
(根据 John 的建议进行了更改。但我无法处理 Bitmap,这必须由函数的调用者完成)