Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to wipe a piece of image and replace it with trasparency

I did this:

VB
Dim aw As UInteger = com.tilesizewidth
        Dim ah As UInteger = com.tilesizeheight
        If multisel Then
            aw = Abs(pnt2.X - pnt.X)
            ah = Abs(pnt2.X - pnt.X)
            multisel = False
            drawselrect = False
            selectedfirstpnt = True
        End If

        'Dim cloneimg = sourceimg.Clone()
        Using g As Graphics = Graphics.FromImage(sourceimg)
            'g.DrawRectangle(New Pen(New TextureBrush(cloneimg)), pnt.X, pnt.Y, aw, ah)
            g.FillRegion(Brushes.Trasparent, New Region(New Rectangle(pnt.X, pnt.Y, aw, ah)))
            'g.FillRegion(Brushes.White, New Region(New Rectangle(pnt.X, pnt.Y, aw, ah)))
        End Using

        imgsaved = False
        pic.Invalidate()


g.FillRegion(Brushes.Trasparent, New Region(New Rectangle(pnt.X, pnt.Y, aw, ah))) don't work

g.FillRegion(Brushes.White, New Region(New Rectangle(pnt.X, pnt.Y, aw, ah))) works but it's white!!
Posted

1 solution

this is my ugly solution for now!

VB
Dim aw As UInteger = com.tilesizewidth + pnt.X
        Dim ah As UInteger = com.tilesizeheight + pnt.Y
        If multisel Then
            aw = pnt2.X
            ah = pnt2.Y
            multisel = False
            drawselrect = False
            selectedfirstpnt = True
        End If

        Dim edit = New Bitmap(sourceimg)
        For i As Integer = pnt.X To aw
            For j As Integer = pnt.Y To ah
                edit.SetPixel(i, j, Color.Transparent)
            Next
        Next

        sourceimg = edit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900