本文介绍了Winforms C#渐变不透明度位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作一个应用了线性不透明度的位图. (即,它在左侧更不透明,而在靠近右侧时逐渐变得不透明.)
I want to make a bitmap that has a linear opacity applied. (i.e. it is more opaque on the left side and get progressively less opaque as it approaches the right.)
这可能吗?我知道它可能具有恒定的不透明度级别.
Is this possible? I know its possible to have a constant opacity level.
推荐答案
因此,请不要使其保持不变,LinearGradientBrush可以轻松插值alpha值.设置了BackgroundImage的表单的简单演示:
So don't make it constant, LinearGradientBrush has no trouble interpolating the alpha value. A simple demonstration of a form that has the BackgroundImage set:
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
var rc = new Rectangle(20, 20, this.ClientSize.Width - 40, 50);
using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(
rc,
Color.FromArgb(255, Color.BlueViolet),
Color.FromArgb(0, Color.BlueViolet),
0f)) {
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
e.Graphics.FillRectangle(brush, rc);
}
}
生产:
这篇关于Winforms C#渐变不透明度位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!