惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
V
Visual Studio Blog
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
IT之家
IT之家
博客园_首页
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - Franky
雷峰网
雷峰网
罗磊的独立博客
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
T
Tailwind CSS Blog
B
Blog RSS Feed
H
Help Net Security
T
The Blog of Author Tim Ferriss
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
C
CERT Recently Published Vulnerability Notes
博客园 - 三生石上(FineUI控件)
P
Palo Alto Networks Blog
I
Intezer
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
S
Securelist
J
Java Code Geeks
V
V2EX
Y
Y Combinator Blog
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog
Forbes - Security
Forbes - Security
Google Online Security Blog
Google Online Security Blog
Help Net Security
Help Net Security
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic

博客园 - HotSky

Chrome启用CDP(chrome-devtools-protocol)进行远程操控 WPF 让ScrollViewer支持按住鼠标中键拖拽滚动内容 WPF 让ScrollViewer支持鼠标中键滚动缩放内容 Nodejs使用 nodejs中写sql需要用in时的写法 C#城市最短路径 C#Animation Sqlite PDF附录A: 内容流操作码 WPF FPS类 生命模拟 C# Sql帮助类,可扩展 WPF WriteableBitmap通过GDI+绘制帮助类 Bmp读写二值图 WPF支持任意快捷键+鼠标组合的绑定类 WPF阻止窗体被系统缩放,使用显示器DPI WPF DataGrid自动增长序号列 C#访问或修改私有类、函数、变量、属性 WPF一个简单的属性编辑控件
Alpha混合
HotSky · 2024-08-03 · via 博客园 - HotSky

算法:

前景颜色值: R1,G1,B1,A1
背景颜色值: R2,G2,B2,A2
则混合后颜色值:
  R = R1 * A1 + R2 * A2 * (1-A1)
  G = G1 * A1 + G2 * A2 * (1-A1)
  B = B1 * A1 + B2 * A2 * (1-A1)
  A = 1 - (1 - A1) * (1 - A2) ;

C#:

public static int[] ColorAlpha(int frontA, int frontR, int frontG, int frontB, int backA, int backR, int backG, int backB)
{
    float n1 = 1f, n255 = 255f;
    if(frontA >= n255)
        return new int[] { frontA, frontR, frontG, frontB };
    float r = frontR * frontA / n255 + backR * backA / n255 * (n1 - frontA / n255);
    float g = frontG * frontA / n255 + backG * backA / n255 * (n1 - frontA / n255);
    float b = frontB * frontA / n255 + backB * backA / n255 * (n1 - frontA / n255);
    float a = (n1 - (n1 - frontA / n255) * (n1 - backA / n255)) * n255;
    return new int[] { (int)a, (int)r, (int)g, (int)b};
}

javascript:

//1前景色;2背景色
function colorAlpha(a1,r1,g1,b1,a2,r2,g2,b2){
    if(a1 >= 255)
        return { a: a1, r: r1, g: g1, b: b1 };
    let r = r1 * a1 / 255 + r2 * a2 / 255 * (1 - a1 / 255);
    let g = g1 * a1 / 255 + g2 * a2 / 255 * (1 - a1 / 255);
    let b = b1 * a1 / 255 + b2 * a2 / 255 * (1 - a1 / 255);
    let a = 1 - (1 - a1/255)*(1-a2/255);
    return {a:a, r: r, g: g, b: b};
}