` Comment on an Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Add a comment to an Icetips Article

Please add your comments to this article. Please note that you must provide both a name and a valid email address in order for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!

Your Name:  
Email:  
Header text/Subject:  

Please enter your comment in the box below:

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Windows API: Saving DIB as BMP
2002-05-26 -- Jim Kane
 
Newsgroups: softvelocity.products.c55ee It depends on what you mean by bitmap. I'm guessing from the title of the email that you mean a dib and have an hdib and not a hbitmap. you need to add a small file header to the dib then write it to disk. The code to add the file header is like this. the code was pull together from two spots so it's possible I missed an equate or two. BmpLibType.SaveDIB PROCEDURE (unsigned hdib, *cstring filename) ! Declare Procedure bisizeimage long bisize long fhandle unsigned byteswritten ulong LphDib Long hDibSize Long hbmpfile unsigned lpbmpfile Long hbmpSize Long BITMAPFILEHEADER GROUP bfType ushort bfSize ulong bfReserved1 ushort bfReserved2 ushort bfOffbits ulong END bmfhSignature string(2),over(bitmapfileheader.bftype) FILE_BEGIN equate(0) FILE_SHARE_READ equate(1) FILE_SHARE_WRITE equate(2) FILE_ATTRIBUTE_NORMAL equate(80H) FILE_ATTRIBUTE_TEMPORARY equate(100H) FILE_FLAG_RANDOM_ACCESS equate(10000000H) FILE_FLAG_SEQUENTIAL_SCAN equate(08000000H) FILE_FLAG_DELETE_ON_CLOSE equate(04000000H) GENERIC_READ equate(80000000H) GENERIC_WRITE equate(40000000H) GENERIC_EXECUTE equate(20000000H) GENERIC_ALL equate(10000000H) CREATE_NEW equate(1) CREATE_ALWAYS equate(2) OPEN_EXISTING equate(3) OPEN_ALWAYS equate(4) TRUNCATE_EXISTING equate(5) CODE hdibsize = GlobalSize(hdib) lphdib = GlobalLock(hdib) memcpy(address(biSizeImage),lphdib+20,4) memcpy(address(bisize),lphdib,4) Bitmapfileheader.bfOffBits = SIZE(BitmapFileHeader)+ | bisize + self.PaletteSize(lphdib) BitMapFileHeader.bfSize = bitmapfileheader.bfOffBits + biSizeImage bmfhSignature = 'BM' ! STRING OVER bmfh.bfType hbmpfile = GlobalAlloc(42H, BitMapFileHeader.bfSize) If ~hbmpfile then globalunlock(hdib) return(3) End lpbmpfile = GlobalLock(hbmpfile) memcpy( lpbmpfile, address(bitmapfileHeader), Size(bitmapfileHeader)) memcpy( lpbmpfile + size(bitmapfileheader), lphdib, | Bitmapfileheader.bfsize - size(bitmapfileheader)) hdibsize = BitMapFileHeader.bfSize globalunlock(hdib) fHandle=CreateFile(FileName,Generic_write,File_Share_Write,0, | Create_Always,FILE_FLAG_SEQUENTIAL_SCAN,0) if fhandle= 0FFFFFFFFH then !message(getlasterror(),'Create File Error') globalFree(hbmpfile) return(3) end WriteFile(fhandle,lpbmpfile,hdibsize,byteswritten,0) closehandle(fhandle) globalfree(hbmpfile) !free memory if byteswritten < hdibsize then Return(3) end Return(0)


Today is November 23, 2024, 2:13 am
This article has been viewed 35224 times.
Google search has resulted in 291 hits on this article since January 25, 2004.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: