Question Resize Canvas

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have an image that is 100x100 size. How can i resize the canvas but not the image and make it 200x100 and filling the new space with the color black?
 
There might be a better way to do it, but this is the best I could come up with:

VB.NET:
Public Function Resize(ByVal original As Bitmap, ByVal size As Size, ByVal backColor as Color) As Bitmap
    Dim newImg as New Bitmap(size.Width, size.Height)
    Using g As Graphics = Graphics.FromImage(newImg)
        g.FillRectangle(New SolidBrush(backColor), New Rectangle(Point.Empty, newImg.Size))
        g.DrawImage(original, Point.Empty)
    End Using
    Return newImg
End Function
 
Back
Top