how can i set the transparency of a bitmap that is displayed on the picturebox, i am making a digital makeup software and i want my makeup's tints or colors be reduced or increased. this is the code of that

Public Class foundationfrm
Private SelectedFoundation As Foundation
Private MouseIsDown As Boolean
Private CurrentAction As Action

Public Enum Action
None
Move
ResizeNW
ResizeSW
ResizeLeft
End Enum

Public Class Foundation
Public Pic As Bitmap
Public bBox As Rectangle
Public referencePoint As Point
End Class

Private Sub f1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles f1.MouseDown, f2.MouseDown, f3.MouseDown, f4.MouseDown, f5.MouseDown, f6.MouseDown

Dim thisfoundation As New Foundation
thisfoundation.Pic = CType(CType(sender, PictureBox).Image, Bitmap)

DoDragDrop(thisfoundation, DragDropEffects.All)

End Sub

Private Sub foundationfrm_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter

If e.Data.GetDataPresent(GetType(Foundation)) Then
e.Effect = DragDropEffects.All

End If
End Sub


Private Sub foundatiofrm_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

If e.Data.GetDataPresent(GetType(Foundation)) Then

SelectedFoundation = CType(e.Data.GetData(GetType(Foundation)), Foundation)

If foundationpic.DisplayRectangle.Contains(foundationpic.PointToClient(Cursor.Position)) Then
SelectedFoundation.bBox = New Rectangle(foundationpic.PointToClient(Cursor.Position), SelectedFoundation.Pic.Size)

Else
SelectedFoundation.bBox = New Rectangle(New Point(0, 0), SelectedFoundation.Pic.Size)

End If


foundationpic.Invalidate()
End If
End Sub


Private Sub foundationpic_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles foundationpic.MouseDown


If SelectedFoundation IsNot Nothing Then

CurrentAction = GetAction2(SelectedFoundation.bBox, e.Location)
If CurrentAction <> Action.None Then
MouseIsDown = True
If foundationpic.Cursor = Cursors.Arrow Then foundationpic.Cursor = Cursors.Hand
SelectedFoundation.referencePoint = e.Location
End If
End If

foundationpic.Invalidate()
End Sub

Private Sub foundationpic_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles foundationpic.MouseMove

If SelectedFoundation IsNot Nothing Then

If MouseIsDown Then

Select Case CurrentAction
Case Action.Move

SelectedFoundation.bBox.Location = SelectedFoundation.bBox.Location + (CType(e.Location, Size) - CType(SelectedFoundation.referencePoint, Size))
SelectedFoundation.referencePoint = e.Location

Case Action.ResizeLeft

SelectedFoundation.bBox.X = e.Location.X
SelectedFoundation.bBox.Width += SelectedFoundation.referencePoint.X - e.Location.X
SelectedFoundation.referencePoint = e.Location

Case Action.ResizeNW
SelectedFoundation.bBox.Location = e.Location
SelectedFoundation.bBox.Width += SelectedFoundation.referencePoint.X - e.Location.X
SelectedFoundation.bBox.Height += SelectedFoundation.referencePoint.Y - e.Location.Y
SelectedFoundation.referencePoint = e.Location

End Select

foundationpic.Invalidate()

Else

Select Case GetAction2(SelectedFoundation.bBox, e.Location)
Case Action.None
foundationpic.Cursor = Cursors.Arrow

Case Action.Move
foundationpic.Cursor = Cursors.Hand

Case Action.ResizeLeft
foundationpic.Cursor = Cursors.SizeWE

Case Action.ResizeNW
foundationpic.Cursor = Cursors.SizeNWSE

Case Action.ResizeSW
foundationpic.Cursor = Cursors.SizeNESW

End Select


End If

Else
If Not foundationpic.Cursor = Cursors.Arrow Then foundationpic.Cursor = Cursors.Arrow
End If

End Sub

Private Sub foundationpic_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles foundationpic.MouseUp

MouseIsDown = False
End Sub

Private Sub foundationpic_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles foundationpic.Paint

If SelectedFoundation IsNot Nothing Then
e.Graphics.DrawImage(SelectedFoundation.Pic, SelectedFoundation.bBox)

Dim dotPen As New Pen(Color.Black, 1)
dotPen.DashStyle = Drawing2D.DashStyle.Dot
e.Graphics.DrawRectangle(dotPen, SelectedFoundation.bBox)
dotPen.Dispose()
End If


End Sub

Private Function GetAction2(ByVal found As Rectangle, ByVal ScreenLocation As Point) As Action

found.Inflate(4, 4)

If found.Contains(ScreenLocation) Then

If ScreenLocation.X <= SelectedFoundation.bBox.Left + 4 Then
If ScreenLocation.Y <= SelectedFoundation.bBox.Top + 4 Then
Return Action.ResizeNW
ElseIf ScreenLocation.Y >= SelectedFoundation.bBox.Bottom - 4 Then
Return Action.ResizeSW
Else
Return Action.ResizeLeft
End If

Else
Return Action.Move
End If
Else
Return Action.None
End If

End Function


Private Function GetFinalImage() As Bitmap

Dim finalImage As Bitmap = foundationpic.Image.Clone

Dim g As Graphics = Graphics.FromImage(finalImage)

g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic

g.DrawImage(SelectedFoundation.Pic, SelectedFoundation.bBox)

g.Dispose()


Return finalImage
End Function

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f1.Click

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles donebtn.Click
Try


Dim image As Bitmap
image = GetFinalImage()

blushfrm.blushpic.Image = image
Me.Hide()
blushfrm.Show()
Catch ex As Exception
Dim res = MessageBox.Show("Do you really want to proceed?", "Alert!", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

If res = DialogResult.Yes Then
blushfrm.blushpic.Image = foundationpic.Image
Me.Hide()
blushfrm.Show()
Else
Exit Sub

End If
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearbtn.Click
If SelectedFoundation IsNot Nothing Then

SelectedFoundation = Nothing
foundationpic.Refresh()
End If
End Sub

Private Sub foundationfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

is there any idea on how can i set the transparency of a bitmap image? thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.