首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用alpha混合将ARBG转换为RGB

使用alpha混合将ARBG转换为RGB
EN

Stack Overflow用户
提问于 2008-08-05 20:12:20
回答 2查看 12.9K关注 0票数 25

假设我们有一个ARGB颜色:

代码语言:javascript
复制
Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.

当在现有颜色上绘制此颜色时,颜色将混合。因此,当它与白色混合时,得到的颜色是Color.FromARGB(255, 162, 133, 255);

解决方案应该是这样工作的:

代码语言:javascript
复制
Color blend = Color.White; 
Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.      
Color rgb = ToRGB(argb, blend); //Same as Color.FromARGB(255, 162, 133, 255);

ToRGB的实现是什么?

EN

回答 2

Stack Overflow用户

发布于 2013-06-26 18:52:29

我知道这是一个旧的线程,但我想添加以下内容:

代码语言:javascript
复制
Public Shared Function AlphaBlend(ByVal ForeGround As Color, ByVal BackGround As Color) As Color
    If ForeGround.A = 0 Then Return BackGround
    If BackGround.A = 0 Then Return ForeGround
    If ForeGround.A = 255 Then Return ForeGround
    Dim Alpha As Integer = CInt(ForeGround.A) + 1
    Dim B As Integer = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8
    Dim G As Integer = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8
    Dim R As Integer = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8
    Dim A As Integer = ForeGround.A

    If BackGround.A = 255 Then A = 255
    If A > 255 Then A = 255
    If R > 255 Then R = 255
    If G > 255 Then G = 255
    If B > 255 Then B = 255

    Return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B))
End Function

public static Color AlphaBlend(Color ForeGround, Color BackGround)
{
    if (ForeGround.A == 0)
        return BackGround;
    if (BackGround.A == 0)
        return ForeGround;
    if (ForeGround.A == 255)
        return ForeGround;

    int Alpha = Convert.ToInt32(ForeGround.A) + 1;
    int B = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8;
    int G = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8;
    int R = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8;
    int A = ForeGround.A;

    if (BackGround.A == 255)
        A = 255;
    if (A > 255)
        A = 255;
    if (R > 255)
        R = 255;
    if (G > 255)
        G = 255;
    if (B > 255)
        B = 255;

    return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B));
}
票数 4
EN

Stack Overflow用户

发布于 2008-08-06 06:39:12

如果你不需要知道这个预渲染,我相信你可以使用getpixel的win32方法。

注意:在密苏里州中部的iPhone上打字,不能上网。我将查找真实的win32示例,并查看是否存在与.net等效的示例。

如果有人关心,并且不想使用上面发布的(很好的)答案,您可以通过此链接MSDN example获取.Net中像素的颜色值

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档