0

2 つの色を取り、それらの混合バージョンを返す関数が必要なだけです。GDI と同じ方法で混合する必要があります。

GDI で 2 つの ARGB 色を混合したときに得られるアルファ値は、次のように計算されると考えました。

Private Function blend(alphaBelow As Single, alphaAbove As Single) As Single
    Return alphaBelow + (1.0 - alphaBelow) * alphaAbove
End Function

また、Microsoft が R、G、B の値は次の式を使用して計算されると述べているこのページも見つけました。

displayColor = sourceColor × alpha / 255 + backgroundColor × (255 – alpha) / 255

ただし、それを機能させることはできません:

Color1:          A=164, R=111, G=78, B=129
Color2:          A=241, R=152, G=22, B=48
Blended in GDI:  A=250, R=150, G=24, B=50

R:
150 = 152 * x / 255 + 111 * (255 - x) / 255
x = 9945/41 = 242.5609756097560975609756097561

G:
24 = 22 * x / 255 + 78 * (255 - x) / 255
x = 6885/28 = 245.89285714285714285714285714286

B:
50 = 48 * x / 255 + 129 * (255 - x) / 255
x = 6715/27 = 248.7037037037037037037037037037

ご覧のとおり、R、G、B の値ごとに異なるアルファ値を取得しています。この数はどのように計算されますか?

編集:

Color1 と Color2 は、混ぜ合わせたいランダムな ARGB カラーです。「Blended in GDI」は、ビットマップでそれらを重ねて描画すると得られるものです。

色を GDI と混合するコード:

    Dim B As New Bitmap(Width, Height, Imaging.PixelFormat.Format32bppPArgb)
    Dim G = Graphics.FromImage(B)
    Dim w = B.Width - 1, h = B.Height - 1

    G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

    Dim pth As New Drawing2D.GraphicsPath
    pth.AddRectangle(New Rectangle(0, 0, w, h))

    Dim c1 = RandomColor(), c2 = RandomColor()
    G.FillPath(New SolidBrush(c1), pth)
    G.FillPath(New SolidBrush(c2), pth)

    Dim resoult As Color = B.GetPixel(w / 2, h / 2)
4

1 に答える 1