help with saving a DIB after I write to it simulating a text file.

Started by jklosak, December 08, 2009, 05:24:36 PM

Previous topic - Next topic

jklosak

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??????????????????????
      

jj2007

Search the forum for GetDiBits. I am pretty sure there are plenty of examples around.

jklosak

I think GetDIBbits requires the source to be a DDB not a DIB.?

jj2007

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, and search in the page for Bingo.

jklosak

????????? Bingo????????????????? 100s of pages. none helpful. :(

jj2007

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.

jklosak

wow    :( you just made another DIB........
maybe someone else has a fresh approach to saving a BMP to file from a DIB.

jklosak

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.

rags

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......
God made Man, but the monkey applied the glue -DEVO

sinsi

Have you tried GDI+ functions? A couple to look at would be GdipCreateFromHBITMAP and GdipSaveImageToFile.
Light travels faster than sound, that's why some people seem bright until you hear them.

jklosak

I have tried GDI fuctions for the last 48 hours with little success. I need the bits of the DIB.

sinsi

Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

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
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, but I don't think that JimG would be happy to answer... ::)

sinsi

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
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, 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
Light travels faster than sound, that's why some people seem bright until you hear them.

japheth

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".