Hi everyone.
I'm having trouble with the below function that i wrote.
It is supposed to extract a new bitmap (of the specified size) from the supplied bitmap and return it.
But the problem is, every time i run it (I've tried supplying it with various different bitmaps) it returns a blank image of the correct size.
For example, i might do:
Dim img as Bitmap = sprite_SubImage(My.Resources.testImage, New Size(32, 32), New Point(0, 0))
img.Save("C:\test.bmp")
But test.bmp just ends up being a blank image. (Even when My.Resources.testImage is simply a 50x50 red image)
Can anyone advise on what I'm doing wrong?
Thanks in advance
Function is below:
Private Function sprite_SubImage(ByVal source As Bitmap, ByVal subsize As Size, ByVal loc As Point) As Bitmap
'Returns a Bitmap which is cut from a specified resource at certain coords and size specifications
Dim tmpImg As New Bitmap(subsize.Width, subsize.Height)
Dim gr As Graphics = Graphics.FromImage(source)
gr.DrawImage(tmpImg, 0, 0, New RectangleF(locx, locy, subsize.Width, subsize.Height), GraphicsUnit.Pixel)
Return tmpImg
End Function
I'm having trouble with the below function that i wrote.
It is supposed to extract a new bitmap (of the specified size) from the supplied bitmap and return it.
But the problem is, every time i run it (I've tried supplying it with various different bitmaps) it returns a blank image of the correct size.
For example, i might do:
Dim img as Bitmap = sprite_SubImage(My.Resources.testImage, New Size(32, 32), New Point(0, 0))
img.Save("C:\test.bmp")
But test.bmp just ends up being a blank image. (Even when My.Resources.testImage is simply a 50x50 red image)
Can anyone advise on what I'm doing wrong?
Thanks in advance
Function is below:
Private Function sprite_SubImage(ByVal source As Bitmap, ByVal subsize As Size, ByVal loc As Point) As Bitmap
'Returns a Bitmap which is cut from a specified resource at certain coords and size specifications
Dim tmpImg As New Bitmap(subsize.Width, subsize.Height)
Dim gr As Graphics = Graphics.FromImage(source)
gr.DrawImage(tmpImg, 0, 0, New RectangleF(locx, locy, subsize.Width, subsize.Height), GraphicsUnit.Pixel)
Return tmpImg
End Function