On line 8, you draw bmp
onto bmp2
. Anything you do afterwards with gfx
still affects bmp2
.
On line 9, you created a new bitmap and assigned gfx
to the bitmap, implying you'd draw onto bmp
with gfx
(which you didn't anyway). You then proceed to save bmp
which gave you an empty, or as you describe it, "transparent" image.
If you're trying to double the size of your image, you might consider revising your code to something of this sort:
Private Sub DrawNewImage()
Dim bmp = New Bitmap("C:\Path\to\file.bmp")
Dim Width = bmp.Width
Dim Height = bmp.Height
Dim w2 As Integer = PowerOf2(Width)
Dim h2 As Integer = PowerOf2(Height)
Dim bmp2 = New Bitmap(w2, h2)
Dim gfx = Graphics.FromImage(bmp2)
gfx.DrawImage(bmp, 0, 0, w2, h2)
bmp2.Save("C:\Path\to\saved\file.bmp")
End Sub
Private Function PowerOf2(ByVal value As Integer) As Integer
Return value * value
End Function
or you can try the converted C# version:
private void DrawNewImage()
{
Bitmap bmp = new Bitmap("C:\\Path\\to\\file.bmp");
int Width = bmp.Width;
int Height = bmp.Height;
int w2 = PowerOf2(Width);
int h2 = PowerOf2(Height);
Bitmap bmp2 = new Bitmap(w2, h2);
Graphics gfx = Graphics.FromImage(bmp2);
gfx.DrawImage(bmp, 0, 0, w2, h2);
bmp2.Save("C:\\Path\\to\\saved\\file.bmp");
}
private int PowerOf2(int value)
{
return value * value;
}