none
Jak překrýt Bitmap barvou? RRS feed

  • Dotaz

  • Dobrý den, jsem začátečník ve visual basicu a mám takovýto kód, vím že je to paskvil ale to ted prosím neřešte, potřebuji poradit jak udělat v třetím řádku od spodu následující (něco na tenhle způsob, s touhle funkcí):

    If True And Form2.Button2.BackColor = Color.Red Then New Bitmap(zkouska1)BackColor = Color.Red

    Chápete? aby Když vyvolám ten "klik" který je řešený posledním odstavcem v kódu a ten button2 na Forme2 bude zároveň červený, potrebuju aby se tedy ta vykreslena bitmapa (zkouska1) prebarvila do cervene barvy...

    Public Class zkouska1
        Private _zkouska1 As New Bitmap("C:\Users\w\Desktop\brno_skola\reduta\Program\Bila\1.png")
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            Form1.Show()
            Form2.Show()
            MyBase.OnPaint(e)

            e.Graphics.DrawImageUnscaled(New Bitmap(_zkouska1), 0, 0)
        End Sub
        Private Sub zkouska1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            MyNewSub()
        End Sub

        Sub MyNewSub()
            BackColor = Color.Red
            TransparencyKey = BackColor
        End Sub
        Private Sub Example_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded

            AddHandler e.Control.MouseClick, AddressOf Example_MouseClick
        End Sub

        Private Sub Example_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
            If True And Form2.Button2.BackColor = Color.Red Then ??? řešení ???
        End Sub
    End Class


    Pomohlo by neco z tohohle?:

    To set a single color for a bitmap you can use:

    Public Function GetColoredBitmap(w as Integer,
                                     h as Integer,
                                     col as Color) as Bitmap
    
        Dim bmp as New Bitmap(w, h, PixelFormat32bppPARGB)
        Using g as Graphics = Graphics.FromImage(bmp)
            g.Clear(col)
        End Using
    
        Return bmp
    
    End function
    

    Incorporate as needed. One way is to do this:

    Private sub Button2_Clicked(s as object, e as eventargs) handles Button2.Click
    
        Dim bmp as bitmap = GetColoredBitmap(100, 100, Button2.BackColor)
        bmp.SaveAs("path/to/file.png")
        bmp.Dispose
    
    End sub
    

    Update:

    To alter an existing bitmap, modify to:

    Public Sub ColorBitmap(bmp as Bitmap, col as Color)
    
        Using g as Graphics = Graphics.FromImage(bmp)
            g.Clear(col)
        End Using
    
    End Sub
    
    • Upravený klikihak sobota 5. ledna 2013 16:26
    pátek 4. ledna 2013 17:30