BMP File Saving
I was wondering if anyone knows of an easy to use library which can save HBITMAPs to .BMP files. I have searched the internet for it and have found many examples but most of them seemed to advanced, and non were able to save HBITMAPs to .BMP. I know theres a function to do this in VB, i was wondering if there was a function to do this in C. If possible can it be pure Win32, and as easy to understand as possible.
sounds form ur post that ur mainly a vb programmer soo.....
1) shld u be placing this on a c board??
2) hope the below helps ^^
i too have tried this with no result, if you are using vb u know of the nice pre-made save picture command however you can only save ipicture resources and unless you use the render command from a buffer hdc (which requires com structs yuk [ole]) then you will have to try the method im using, basically the glue process in vb clipboard.getdata vbpixelmode returns a compatible ipicture.. so have you tried using the api calls openclipboard and setclipboard data (both user32) and well simply shoving data onto clipboard from the hbmp dc surface (or buffer if u will) and then using the vb procs to retrieve them in ipicture format then using the savepicture command?
ahh the good old days of vb
firstly thanx 4 the reply
secondly, lol i stopped programming in vb a couple of months back and started c++, but ive seen an algorithm which can save a dd7 surface to a .Bmp file on these boards:
the link: http://cboard.cprogramming.com/showt...threadid=30342
i was wondering if anyone knew how instead of the algorithm saving from a dd7 surface, it could save from a HBITMAP.
Or if anyone knows of a library/header which can save HBITMAPs to .BMP files, ive searched MSDN and found something called GDI+, but it doesnt explain what i have to include in order to use its members.
Can someone please take a look at the thread and show me how i could make it work for HBITMAPs, any help would be appreciated.
have u ever thought of trying the grueling task of using get pixel and printing each pixel into hex in a file lol the manual bitmap saving way, this does work i have done it before but it is v.slow like 1 minute to save 800x600 image i.e screen shot
lol ya i did try that and your right it was slow, but this program is meant to be as fast as possible. The whole concept of the program is to intercept PrntScreen messages, and then take a snapshot of the whole desktop and automatically save this as a .BMP file.
The reason i chose C++ for it is because i know its much faster than VB, and its way easier than ASM.
So basically im only looking for an algorithm which just saves a HBITMAP as a BMP file. I figured out how to do the screenshot part, just the saving part is all that remains.
if u find a funtion in the api like that tell me about it plz ^^ it wld improve some of my applications 10 fold ^^, i know of the direct draw function, but altho u can blit to the surface of a direct draw buffer it doesnt hold it does it, i.e u cant then just use the dd7 save command as it would just save a black screen wouldnt it??
lol neway the way i see this application.. it would be faster done in vb... *gasp* if the application was to be tho say a picture editor then c++ would be the better option faster cleaner more reliable and doesnt require the anoying dll and ocx includes :P however in this situation to do the program in vb u wldnt even require the use of buffers.. u could force the keyboard event print screen key (which we all know shoves a screen capture into memory) then using savepicture with clipboard.getdata it wld take u about 3 lines, in c++ tho it would be awkward and i almost gurantee that no one if any will give u a straight answer other than something like go here www.msdn.com lol or research com
i did a search on MSDN and i did find a method to convert an HBITMAP to a .BMP file, but it required GDI+, i have no idea where to get it, i searched MSDN for it and i got a link for it but it was only for Windows 9x, i have Windows XP but i dont know which libraries to link and which headers files to include.
Also i did make one in VB but since i converted to C++, im trying to convert all my VB projects into C++ projects as a learning experience. And since most of the programs i make i upload to a fan website where hundreds of people download them, im required to make it as small as possible and that cant be done on Visual Basic.
Also its much easier to upload 1 .exe rather than an exe and a whole bunch of dlls.
I hope theres someone out there with the answer lol, im pretty sure that someone somewhere must have used this atleast once. I mean how do they make all the paint programs in C++?
Again thanx for your help MicroFiend, its greatly appreciated.
hmm gdi plus sounds interesting, if its the same style as the advapi32.dll (a new set with functions like trancparent blit) then it should be covered by windows.h (this may be not included tho if ur add in the windows_lean_and_mean comment in the header
lol i only changed from vb 2 c about a year ago i did exactly the same as what ur doing (lol isnt c++ a brieze when u are an indepth windows api programmer) how r u finding the change? i bet it was a shock with all the typcasting, pointers and strange data types (like with vb where they stor the hdc and hbmp as longs lol but in c++ u define HDC and HANDLE ^^)
cmon some1 post something useful too help the guy out, the only reason i keep rampbling on is to keep the thread on top in the main board ^^, i hate a question with no answer, its like a if statement with no function.... a useless do nothing if statement.... okay maybee i shuld leave off the e numbers ^^
some1 post summin useful
I don't know if this is of any help?
Honestly, BMP is just a "Device Independant Bitmap" with a BITMAPFILEHEADER stuck on the front. Simply write out your BITMAPFILEHEADER structure and then write out the results of a GetDIBits() call. Done.
Do NOT under any circumstance, use GetPixel() type calls. Each GDI call you make slows you down dramatically.
thanx alot 4 the replies guys, and MicroFiend, i really appreciate your help yet again
I found the transition from VB to C easy, well ur right about the API calls and stuff, but also the syntax.
The only thing i dont really understand is why they dont have functions like the ones in vb lol, like a save to bitmap function or sumthing.. oh well its a price to pay, also the object-orientated way of programming is kinda hard for me, lol writing a whole window class killed me, oh well im gonna search those sites you guyz posted and hopefully ill find the answer, btw if anyone has any other links can you please post it
I'm going with FillYourBrain on this one, and a quick flick through MSDN brought this up:
I expect the code there will do what you require although if you're interested how it works then I'm sure the comments will give you some idea
Also, this page explains the Bitmap file structures which would shed some light on what exactly the functions above are achieving:
Note that this link has some coding errors (I think it does not work for bitmaps > 256 colors) and explanation errors (they talk about one structure when they mean the other), so you should read the comments. I am not even sure if all of the comments point out all of the errors. They should update the page - I just wrote them an email to do so, so no further people will be mislead by it.
Originally posted by knutso I don't know if this is of any help?