The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: jklosak on December 08, 2009, 05:24:36 PM

Title: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 08, 2009, 05:24:36 PM
Basically I need help saving a BMP.

                LOCAL Buffer1 [1000]:BYTE   ;local buffer
   LOCAL lpBuffer1:DWORD
   LOCAL bmi:BITMAPINFO
   LOCAL bmih:BITMAPINFOHEADER
   LOCAL hDC:DWORD
   LOCAL imageDC:DWORD
   LOCAL hbitmap:DWORD
   

                ;Define a BITMAPINFO and fill it
      LEA eax,DWORD PTR bmi
      mov edi,eax
      assume edi:ptr BITMAPINFO
         mov [edi].bmiHeader.biSize,SIZEOF BITMAPINFOHEADER
         mov [edi].bmiHeader.biWidth,1728
         mov [edi].bmiHeader.biHeight,-2290
         mov [edi].bmiHeader.biPlanes,1
         mov [edi].bmiHeader.biBitCount,1
         
         mov [edi].bmiColors[1].rgbBlue,0FFh
         mov [edi].bmiColors[1].rgbGreen,0FFh
         mov [edi].bmiColors[1].rgbRed,0FFh
      assume edi:nothing
      
                               ;Create DC compatible with the monitor as null
      invoke CreateCompatibleDC,0
      mov hDC,eax
      ;Create DIB
      invoke CreateDIBSection,hDC,ADDR bmi,DIB_RGB_COLORS,pvBits,0,0   ;so you have a B/W DIB section
                                mov hbitmap,eax
      invoke SelectObject,hDC,hbitmap
      mov oldbitmap,eax   ;to delete this object later
      invoke PatBlt,hDC,0,0,1728,2290,WHITENESS
      invoke SetTextAlign,hDC,TA_UPDATECP
      invoke lstrlen,lpBuffer1
      invoke TextOut,hDC,0,0,lpBuffer1,eax         ;to write on the BMP
                                ;NOW HOW DO I SAVE THE BMP FROM THE hDC I CREATED??????????????????????
      
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jj2007 on December 08, 2009, 05:28:28 PM
Search the forum for GetDiBits. I am pretty sure there are plenty of examples around.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 08, 2009, 09:58:46 PM
I think GetDIBbits requires the source to be a DDB not a DIB.?
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jj2007 on December 08, 2009, 10:44:50 PM
Quote from: jklosak on December 08, 2009, 09:58:46 PM
I think GetDIBbits requires the source to be a DDB not a DIB.?

You are right. I did that stuff years ago in 16-bit Windows, and don't remember all the details. Look at this page (http://www.codeguru.com/forum/showthread.php?t=412541), and search in the page for Bingo.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 08, 2009, 11:13:58 PM
????????? Bingo????????????????? 100s of pages. none helpful. :(
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jj2007 on December 08, 2009, 11:24:24 PM
I wrote search in the page for Bingo:

QuoteBingo: now I can throw away all the device contexts and access the bits of the DIBSection directly.

However I had the gut feeling that this was rather long-winded. Obviously GetDIBits was the slow bit, as that's where the conversion has to occur (since there is no guarantee that the CompatibleDC is in the same format as my DIBSection).

Now, as per your suggestion, I tried the much simpler approach of:
Code:

CreateDC (screen)
CreateCompatibleDC
CreateDIBSection
Select DIBSection into CompatibleDC
BitBlt from screen to CompatibleDC (thereby 'painting' the DIBSection)

This seems to work a treat -- great.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 09, 2009, 12:05:43 AM
wow    :( you just made another DIB........
maybe someone else has a fresh approach to saving a BMP to file from a DIB.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 09, 2009, 01:21:27 AM
I would love some help with this. Not fairy tales from Italy. I need to access the bytes from a DIB and save them as a BMP as I initialy outlined. any real help much appreciated.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: rags on December 09, 2009, 01:49:30 AM
QuoteI would love some help with this. Not fairy tales from Italy.
I think that was a fairly rude statement, considering he was just trying to help you.
I think a reading of the forum rules would be helpful, especially #4:
Quote4. There will be no abuse or insults towards other members......
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: sinsi on December 09, 2009, 02:12:10 AM
Have you tried GDI+ functions? A couple to look at would be GdipCreateFromHBITMAP and GdipSaveImageToFile.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 09, 2009, 02:19:30 AM
I have tried GDI fuctions for the last 48 hours with little success. I need the bits of the DIB.
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: sinsi on December 09, 2009, 02:45:31 AM
This MSDN page has some code that saves to a file - Capturing an Image (http://msdn.microsoft.com/en-us/library/dd183402(VS.85).aspx)
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jj2007 on December 09, 2009, 07:17:27 AM
Quote from: sinsi on December 09, 2009, 02:45:31 AM
This MSDN page has some code that saves to a file - Capturing an Image (http://msdn.microsoft.com/en-us/library/dd183402(VS.85).aspx)
Attention, Sinsi, that link contains a call to GetDIBits. Given your photo, you risk another WOW WOW from our friendly new member :green
We could have given him a link to this post (http://www.masm32.com/board/index.php?topic=10850.msg82557#msg82557), but I don't think that JimG would be happy to answer... ::)
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: sinsi on December 09, 2009, 07:23:28 AM
Quote from: jj2007 on December 09, 2009, 07:17:27 AM
Quote from: sinsi on December 09, 2009, 02:45:31 AM
This MSDN page has some code that saves to a file - Capturing an Image (http://msdn.microsoft.com/en-us/library/dd183402(VS.85).aspx)
Attention, Sinsi, that link contains a call to GetDIBits. Given your photo, you risk another WOW WOW from our friendly new member :green
We could have given him a link to this post (http://www.masm32.com/board/index.php?topic=10850.msg82557#msg82557), but I don't think that JimG would be happy to answer... ::)

QuoteA nod is as good as a wink to a blind horse
:wink
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: japheth on December 09, 2009, 02:48:45 PM
Quote from: rags on December 09, 2009, 01:49:30 AM
QuoteI would love some help with this. Not fairy tales from Italy.
I think that was a fairly rude statement, considering he was just trying to help you.

I disagree. This little clap on JJ's head was well deserved. "Good intentions" is no excuse at all, given that a considerable amount of the evil things happening on earth is done by people with "good intentions".
Title: Re: help with saving a DIB after I write to it simulating a text file.
Post by: jklosak on December 09, 2009, 10:14:55 PM
Thanks for all the suggestions. I will keep working on this the next couple days. I know it is doable and these pointers should help get it done.
Have a nice Holiday.
jjk