News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Saving a Memory DC to a bitmap file

Started by Brett Kuntz, June 25, 2005, 11:08:39 AM

Previous topic - Next topic

donkey

Actually, I uploaded a new version today but for something unrelated. Perhaps I had fixed a bug and not uploaded the code at some point. The code today was a small mod to add the IID for IPicture directly to the lib instead of requiring it to be added via the ComDef.inc file. There was a problem importing IPicture using MASM that was not present in GoAsm. It is also possible that the last time I updated the website I uploaded the wrong file. I do remember changing the conversion function sometime last February.

I am sorry about that, I am usually pretty good at updates and such but obviously I fell short here.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Brett Kuntz

Ah ok, well the full/new library looks great. Works like a charm now, just have to figure out how to do my TextOut's and I should be set. Alright, got everything to work now, this was my final code:


    local hbmp:dword
    local hfile:dword
    local hdc:dword

    invoke BitmapFromFile, addr jpgcachename
    mov hbmp, eax
    invoke CreateCompatibleDC, 0
    mov hdc, eax
    invoke SelectObject, hdc, hbmp
    mov hbmp, eax
    invoke TextOut, hdc, 0, 0, addr testtext, sizeof testtext
    invoke SelectObject, hdc, hbmp
    mov hbmp, eax
    invoke DeleteDC, hdc
    invoke ConvertToDIB32, hbmp
    mov hbmp, eax
    invoke CreateFile, addr filen, FILE_ALL_ACCESS, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
    mov hfile, eax
    invoke SaveDIB32, hbmp, hfile
    invoke CloseHandle, hfile
    ret

Faiseur

I discovered the graphic library of Donkey and I play with :-) Thanks.  By testing the code of kuntor I made a small function which can be called to draw text in a Bitmap.

   Paramters:
   hBitmap = Handle to the bitmap (compatible bitmap or 32bit DIB section)
   Text = text to draw
   Color = text color (background is transparent)
   hFont = font (0 = default)
   px = position x
   py = position y

   Original bitmap handle is modified



DIBText PROC uses ebx,hBitmap,Text,Color,hFont,px,py:DWORD

  mov ebx, FUNC (CreateCompatibleDC, 0)
  mov hBitmap, FUNC(SelectObject,ebx, hBitmap)
  invoke  SetBkMode,ebx,TRANSPARENT
  invoke  SelectObject,ebx,hFont
  invoke  SetTextColor,ebx,Color
  invoke TextOut,ebx, px, py,Text,len(Text)
  mov hBitmap, FUNC(SelectObject,ebx, hBitmap)
  invoke DeleteDC,ebx
  ret
DIBText endp

French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/