Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird behavior Saving a Bitmap File

Status
Not open for further replies.

cosmoh2o

Programmer
Jul 22, 2002
92
0
0
US
Please help,

I am trying to save a .bmp file from a BitMap object in VB .NET and it saves, but the file is always "solid" black. If I save it as a PNG file it looks as it should, however I need it in a BMP. Has anyone out there had a similar problem, if so how did you solve it? I have been trying for days and get nowhere. The code is pasted below:

...
m_Bitmap.Save("C:\Testing.bmp", m_Bitmap.RawFormat.Bmp)
m_Bitmap.Dispose()
m_Bitmap = Nothing

The value of m_Bitmap has been set prior to calling Save. I tested it by placing it in another PictureBox value in my VB form and it showed as it should.
Thanks in advance to anyone with an idea.
 
I figured it out. It turns out that calling ".Save" directly on a file to be stored as a BMP won't work. I had to convert it before saving it using the following code as a method:

Bitmap dest = new Bitmap(xSize, ySize)
Graphics gfx = Graphics.FromImage(dest)
gfx.DrawImage(img, 0, 0, xSize, ySize)
return System.Drawing.Image.FromHbitmap(dest.GetHbitmap())

where "img" is the PictureBox Image.

After calling this method I could save the returned image as a BMP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top