Image transparent and apply to other image

gooden

Active member
Joined
May 18, 2007
Messages
32
Programming Experience
Beginner
well i have 2 pictures and i whant to make a efect at the second image and then aply the result in the 1 image.

1 image:
out11tj3.png


2 image or so called mask:
out11mqc7.png



the code i have in the first button it makes the change color of the mask from red to green and then in the 2 button it makes the transparent and it passes to picturebox4

now i whanted a button that take the picturebox1 and the picturebox4 and join togheter to create the outfit with the mask color.

and save that on picturebox5 :|

somebody can help??? the code is \/

VB.NET:
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim originalBMP As New Bitmap(PictureBox2.Image)

        ' //make a copy so original will still be available
        Dim swappedBMP = New Bitmap(originalBMP)
        Dim g As Graphics = Graphics.FromImage(swappedBMP)

        ' // Create a color map.

        Dim MyColorMap(0) As ColorMap
        MyColorMap(0) = New ColorMap()
        MyColorMap(0).OldColor = Color.Red
        MyColorMap(0).NewColor = Color.Green

        '// Create an ImageAttributes object, and call SetRemapTable
        Dim imageAttr As New ImageAttributes()
        imageAttr.SetRemapTable(MyColorMap)

        ' //overdraw the bitmap with swapped colors
        g.DrawImage(swappedBMP, New Rectangle(0, 0, swappedBMP.Width, swappedBMP.Height), 0, 0, swappedBMP.Width, swappedBMP.Height, GraphicsUnit.Pixel, imageAttr)

        PictureBox3.Image = swappedBMP
        Dim ga As Graphics = Me.PictureBox3.CreateGraphics()
        ga.Clear(Me.BackColor)
        Dim rect As New Rectangle(20, 20, 200, 100)
        Dim bitmap As Bitmap = Me.PictureBox3.Image
        Dim ptsArray As Single()() = {New Single() {1, 0, 0, 0, 0}, New Single() {0, 1, 0, 0, 0}, New Single() {0, 0, 1, 0, 0}, New Single() {0, 0, 0, 0.5F, 0}, New Single() {0, 0, 0, 0, 1}}
        Dim clrMatrix As New ColorMatrix(ptsArray)
        Dim imgAttributes As New ImageAttributes
        imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)
        ga.DrawImage(bitmap, New Rectangle(0, 0, PictureBox3.Width, PictureBox3.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, imgAttributes)
        ' Dispose
        PictureBox4.Image = bitmap
        ga.Dispose()
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim g As Graphics = Me.PictureBox3.CreateGraphics()
        g.Clear(Me.BackColor)
        Dim rect As New Rectangle(20, 20, 200, 100)
        Dim bitmap As Bitmap = Me.PictureBox3.Image
        Dim ptsArray As Single()() = {New Single() {1, 0, 0, 0, 0}, New Single() {0, 1, 0, 0, 0}, New Single() {0, 0, 1, 0, 0}, New Single() {0, 0, 0, 0.5F, 0}, New Single() {0, 0, 0, 0, 1}}
        Dim clrMatrix As New ColorMatrix(ptsArray)
        Dim imgAttributes As New ImageAttributes
        imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)
        g.DrawImage(bitmap, New Rectangle(0, 0, PictureBox3.Width, PictureBox3.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, imgAttributes)
        ' Dispose
        g.Dispose()
    End Sub
 
mask and effects

In first place hello and Congratz for you knowleg on vb.net :)

well the reason i'm sending this message is to you to see if you could help me on making a mask but with the efect that you did on this post:

http://www.vbdotnetforums.com/showpost.php?p=55419&postcount=11


the code i have is very simple. it change the color (red and change to green. but then i whant to aply that color with you effect to the mask.

code i have
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim originalBMP As New Bitmap(PictureBox2.Image)

        ' //make a copy so original will still be available
        Dim swappedBMP = New Bitmap(originalBMP)
        Dim g As Graphics = Graphics.FromImage(swappedBMP)

        ' // Create a color map.

        Dim MyColorMap(0) As ColorMap
        MyColorMap(0) = New ColorMap()
        MyColorMap(0).OldColor = Color.Red
        MyColorMap(0).NewColor = Color.Green

        '// Create an ImageAttributes object, and call SetRemapTable
        Dim imageAttr As New ImageAttributes()
        imageAttr.SetRemapTable(MyColorMap)

        ' //overdraw the bitmap with swapped colors
        g.DrawImage(swappedBMP, New Rectangle(0, 0, swappedBMP.Width, swappedBMP.Height), 0, 0, swappedBMP.Width, swappedBMP.Height, GraphicsUnit.Pixel, imageAttr)

        PictureBox3.Image = swappedBMP
        Dim ga As Graphics = Me.PictureBox3.CreateGraphics()
        ga.Clear(Me.BackColor)
        Dim rect As New Rectangle(20, 20, 200, 100)
        Dim bitmap As Bitmap = Me.PictureBox3.Image
        Dim ptsArray As Single()() = {New Single() {1, 0, 0, 0, 0}, New Single() {0, 1, 0, 0, 0}, New Single() {0, 0, 1, 0, 0}, New Single() {0, 0, 0, 0.5F, 0}, New Single() {0, 0, 0, 0, 1}}
        Dim clrMatrix As New ColorMatrix(ptsArray)
        Dim imgAttributes As New ImageAttributes
        imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)
        ga.DrawImage(bitmap, New Rectangle(0, 0, PictureBox3.Width, PictureBox3.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, imgAttributes)
        ' Dispose
        PictureBox4.Image = bitmap
        ga.Dispose()
    End Sub

original:
out11qn1.png


mask:
out11mwj0.png


result:
finalqv4.png


The result have to be like this. and the efect that you did on the post is that :) but i dont know how to aply it :S can you help??

Glad if you could help me.
 
VB.NET:
'imports system.drawing.imaging
Sub merge_and_remap()
    Dim original As New Bitmap("out11tj3.png")
    Dim overlay As New Bitmap("out11mqc7.png")
    Dim g As Graphics = Graphics.FromImage(original)
    Dim imageAttr As New ImageAttributes

    ' color map.
    Dim MyColorMap(0) As ColorMap
    MyColorMap(0) = New ColorMap
    MyColorMap(0).OldColor = Color.Red
    MyColorMap(0).NewColor = Color.Green
    imageAttr.SetRemapTable(MyColorMap)

    ' color matrix (blending)
    Dim ptsArray As Single()() = {New Single() {1, 0, 0, 0, 0}, _
                                  New Single() {0, 1, 0, 0, 0}, _
                                  New Single() {0, 0, 1, 0, 0}, _
                                  New Single() {0, 0, 0, 0.5F, 0}, _
                                  New Single() {0, 0, 0, 0, 1}}
    Dim clrMatrix As New ColorMatrix(ptsArray)
    imageAttr.SetColorMatrix(clrMatrix)

    ' overdraw the bitmap with swapped colors
    g.DrawImage(overlay, _
        New Rectangle(0, 0, overlay.Width, overlay.Height), _
        0, 0, overlay.Width, overlay.Height, _
        GraphicsUnit.Pixel, _
        imageAttr)
    g.Dispose()
    PictureBox1.Image = original
End Sub
The result is this:merged.png
 
Back
Top