0

クラス、継承、およびインターフェイスを使用したプログラミングについてさらに学習するために、RTS スタイルのゲームに取り組んでいます。大きな問題もなく、順調に進んでいます。

私が抱えている問題は、カラーマトリックスにあります。カラー マトリックスを使用して、マップ上にユニットを配置するときに、位置の有効性に応じて緑または赤のオーバーレイを追加します。繰り返しますが、これは次のコードを使用して正常に機能しています (わかりやすくするために切り詰めています)。しかし、画像を半透明にしたいです。

これは私が使用しているコードです。最初にユニットをグレースケールにし、次に赤く着色しますが、半透明にはしません。

Public Overrides Function GetCurrentFrame() As Image
    _AnimationFrame += _AnimationFrameTime
    If _AnimationFrame > 5 Then _AnimationFrame = 0
    Dim CurrentFrame As Image = Nothing

    CurrentFrame = My.Resources.ResourceManager.GetObject("dragoon_walk_l_" & Convert.ToInt16(_AnimationFrame).ToString)

    Dim g As Graphics = Graphics.FromImage(CurrentFrame)

    Dim cm As System.Drawing.Imaging.ColorMatrix = New System.Drawing.Imaging.ColorMatrix(New Single()() _
         {New Single() {0.3, 0.3, 0.3, 0, 0}, _
        New Single() {0.59, 0.59, 0.59, 0, 0}, _
        New Single() {0.11, 0.11, 0.11, 0, 0}, _
        New Single() {0, 0, 0, 1, 0}, _
        New Single() {0.5, 0, 0, 0.5, 1}})

    Dim ia As System.Drawing.Imaging.ImageAttributes = New System.Drawing.Imaging.ImageAttributes()
    ia.SetColorMatrix(cm)
    g.DrawImage(CurrentFrame, New Rectangle(0, 0, CurrentFrame.Width, CurrentFrame.Height), 0, 0, CurrentFrame.Width, CurrentFrame.Height, GraphicsUnit.Pixel, ia)

    g.DrawImage(My.Resources.ResourceManager.GetObject("health" & (Int(20 * (_UnitHealth / _UnitHealthMax)) - 1).ToString), 0, 14)
    g.DrawImage(My.Resources.ResourceManager.GetObject("level" & _Level.ToString), 6, 0)
    g.Dispose()
    Return CurrentFrame
End Function

明確にするために、問題は、カラーマトリックスを使用して画像を赤く半透明にする方法です。

4

1 に答える 1

0

これを2日間見ていて、ちょうど私に来ました。

問題は、空白のビットマップではなく、元の画像からビットマップを作成していたことです。ビットマップの代わりに画像を返していました:(

これは私が使用したソリューションです

Public Overrides Function GetCurrentFrame() As Image
    _AnimationFrame += _AnimationFrameTime
    If _AnimationFrame > 5 Then _AnimationFrame = 0
    Dim CurrentFrame As Image = Nothing

    CurrentFrame = My.Resources.ResourceManager.GetObject("dragoon_walk_l_" & Convert.ToInt16(_AnimationFrame).ToString)

    Dim bm As Bitmap = New Bitmap(CurrentFrame.Width, CurrentFrame.Height)
    Dim g As Graphics = Graphics.FromImage(bm)

    Dim cm As System.Drawing.Imaging.ColorMatrix = New System.Drawing.Imaging.ColorMatrix(New Single()() _
         {New Single() {.3, .3, .3, 0, 0}, _
        New Single() {0.59, .59,.59, 0, 0}, _
        New Single() {.1, 0.1, 0.1, 0, 0}, _
        New Single() {0, 0, 0, 0.75, 0}, _
        New Single() {0.5, 0, 0, 0, 1}})

    Dim ia As System.Drawing.Imaging.ImageAttributes = New System.Drawing.Imaging.ImageAttributes()
    ia.SetColorMatrix(cm)
    g.DrawImage(CurrentFrame, New Rectangle(0, 0, CurrentFrame.Width, CurrentFrame.Height), 0, 0, CurrentFrame.Width, CurrentFrame.Height, GraphicsUnit.Pixel, ia)

    g.DrawImage(My.Resources.ResourceManager.GetObject("health" & (Int(20 * (_UnitHealth / _UnitHealthMax)) - 1).ToString), 0, 14)
    g.DrawImage(My.Resources.ResourceManager.GetObject("level" & _Level.ToString), 6, 0)
    g.Dispose()
    Return bm
End Function
于 2013-03-28T09:58:05.993 に答える