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

推荐订阅源

F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
Last Week in AI
Last Week in AI
V
V2EX
博客园_首页
IT之家
IT之家
Jina AI
Jina AI
博客园 - 叶小钗
The Cloudflare Blog
T
Tailwind CSS Blog
腾讯CDC
B
Blog
D
Docker
L
LangChain Blog
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI

博客园 - HotSky

WPF游标直尺 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};
}