flat assembler
Message board for the users of flat assembler.

Index > Windows > Bitmap Screenshots.

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 03 Oct 2011, 16:28
Hello everyone, does anybody have example how to take bmp screenshots and save it to file and/or display it on window ? Thanks.
Post 03 Oct 2011, 16:28
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 03 Oct 2011, 17:05
edit:
OK, I have done this (found in google.) but I don't know how to save it or display.. anyone help ?
Code:
        invoke CreateDC,<"DISPLAY",0>,0,0,0
        mov [hScreenDC],eax
        invoke CreateCompatibleDC,[hScreenDC]
        mov [hMemDC],eax
        invoke GetDeviceCaps,[hScreenDC],8 ;HORZRES
        mov [x],eax
        invoke GetDeviceCaps,[hScreenDC],10 ;VERTRES
        mov [y],eax
        invoke CreateCompatibleBitmap,[hScreenDC],[x],[y]
        mov [hBitmap],eax
        invoke SelectObject,[hMemDC],[hBitmap]
        mov [hOldBitmap],eax
        invoke BitBlt,[hMemDC],0,0,[x],[y],[hScreenDC],0,0,SRCCOPY
        invoke SelectObject,[hMemDC],[hOldBitmap]
        mov [hBitmap],eax
        invoke DeleteDC,[hMemDC]
        invoke DeleteDC,[hScreenDC]
        ret    
Post 03 Oct 2011, 17:05
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 03 Oct 2011, 17:11
I did this back in the days of Win98 to make blended windows/menus in VB6 Laughing

Use:
Code:
    scrDC = CreateDCA("DISPLAY", "", "", 0)    
to get the screen and then create a bitmap:
Code:
SystemParametersInfoA (SPI_GETWORKAREA, 0, rScreen, 0)
...
    bmTransDC = CreateCompatibleDC(scrDC)
    bmHTrans = CreateCompatibleBitmap(scrDC, tbSize.X, tbSize.Y)
    SelectObject(bmTransDC, bmHTrans)    
and then copy using:
Code:
BitBlt bmTransDC, 0, 0, tbSize.X, tbSize.Y, scrDC, tbPos.X, tbPos.Y, vbSrcCopy    
You can also change the destination DC to a window instead of a bitmap in memory.
Post 03 Oct 2011, 17:11
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho 03 Oct 2011, 17:29
Capturing an Image :
http://msdn.microsoft.com/en-us/library/dd183402(v=VS.85).aspx

Storing an Image :
http://msdn.microsoft.com/en-us/library/dd145119(v=VS.85).aspx
Post 03 Oct 2011, 17:29
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 03 Oct 2011, 18:42
Here is a virtual screen app i made, should help you out.


Description:
Download
Filename: V-screen.zip
Filesize: 15.32 KB
Downloaded: 1117 Time(s)

Post 03 Oct 2011, 18:42
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 03 Oct 2011, 18:49
Thank you guys! I'm going to study now.
Post 03 Oct 2011, 18:49
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 07 Oct 2011, 09:41
tried, tried but unsuccessful. I found some example written in CPP. but I don't understand how to parse this line..
Code:
 DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;    

Here's MSDN src.
http://msdn.microsoft.com/en-us/library/dd183402
Thanks.
Post 07 Oct 2011, 09:41
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 07 Oct 2011, 10:40
I give up. I was trying to capture screen+save to disk but everytime unsucessful. I lost my 3 days without luck. FUCK!
Post 07 Oct 2011, 10:40
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho 07 Oct 2011, 11:20
found this , maybe will help you :

http://win32assembly.online.fr/files/CapScreen.txt
Post 07 Oct 2011, 11:20
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 07 Oct 2011, 12:23
Thank you dancho, that will help me a lot! Smile
Post 07 Oct 2011, 12:23
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 07 Oct 2011, 14:41
Quote:

tried, tried but unsuccessful. I found some example written in CPP. but I don't understand how to parse this line..

That "mess"is just to ensure that each scanline will have a physical length multiple of four. Since in the example by Microsoft biBitCount is set to 32, the expression could be simplified:
Code:
 DWORD dwBmpSize = bmpScreen.bmWidth * 4 * bmpScreen.bmHeight;    
But note that for others bit counts you'll need the original expression.
Post 07 Oct 2011, 14:41
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 07 Oct 2011, 21:41
LocoDelAssembly
Thanks, I'll try that.
-------
I have still problem here, I'm trying to do it with CreateCompatibleBitmap() function instead of CreateDIBSection().. Here's my code but it fails.. What I have missed ?
Code:
format PE GUI 4.0
include 'WIN32AX.INC'
entry main
section '.data' data readable writeable

hdc             dd ?
memdc           dd ?
hFile           dd ?
dwBytes         dd ?
bfilehdr        BITMAPFILEHEADER
binfohdr        BITMAPINFOHEADER
hBitmap         dd ?
dwWidth         dd ?
dwHeight        dd ?
bmpScreen       dd ?
ColorSize       dd ?

section '.text' code readable executable

main:
        invoke GetDC,0
        mov [hdc],eax
        invoke GetSystemMetrics,0
        mov [dwWidth],eax
        invoke GetSystemMetrics,1
        mov [dwHeight],eax
        invoke CreateCompatibleDC,[hdc]
        mov [memdc],eax
        invoke CreateCompatibleBitmap,[hdc],[dwWidth],[dwHeight]
        mov [hBitmap],eax
        invoke SelectObject,[memdc],[hBitmap]
        push eax
        invoke BitBlt,[memdc],0,0,[dwWidth],[dwHeight],[hdc],0,0,SRCCOPY
        mov [ColorSize],eax
        invoke GetObject,[hBitmap],sizeof.BITMAP,bmpScreen
        mov [bfilehdr.bfType],0x4D42
        mov eax,[dwWidth]
        mov edx,[dwHeight]
        mul edx
        mov edx,32
        mul edx
        xor edx,edx
        mul [ColorSize]
        shr eax,3
        add eax,sizeof.BITMAPFILEHEADER
        add eax,sizeof.BITMAPINFOHEADER
        mov [bfilehdr.bfSize],eax
        mov [bfilehdr.bfReserved1],0
        mov [bfilehdr.bfReserved2],0
        mov eax,[ColorSize]
        add eax,sizeof.BITMAPINFOHEADER
        add eax,sizeof.BITMAPFILEHEADER
        mov [bfilehdr.bfOffBits],eax
        mov [binfohdr.biSize],sizeof.BITMAPINFOHEADER
        mov eax,[dwWidth]
        mov [binfohdr.biWidth],eax
        mov eax,[dwHeight]
        mov [binfohdr.biHeight],eax
        mov [binfohdr.biPlanes],1
        mov [binfohdr.biBitCount],32
        mov [binfohdr.biCompression],BI_RGB
        mov [binfohdr.biSizeImage],0
        mov [binfohdr.biXPelsPerMeter],0
        mov [binfohdr.biYPelsPerMeter],0
        mov [binfohdr.biClrUsed],0
        mov [binfohdr.biClrImportant],0
        invoke CreateFile,<"test.bmp",0>,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
        mov [hFile],eax
        invoke WriteFile,[hFile],binfohdr,sizeof.BITMAPINFOHEADER,dwBytes,0
        invoke WriteFile,[hFile],bfilehdr,sizeof.BITMAPFILEHEADER,dwBytes,0
        mov eax,[dwWidth]
        mov edx,[dwHeight]
        mul edx
        shr eax,3
        pop ecx
        invoke WriteFile,[hFile],ecx,eax,dwBytes,0
        invoke CloseHandle,[hFile]
        invoke DeleteObject,[hBitmap]
        invoke DeleteDC,[memdc]
        invoke DeleteDC,[hdc]
ret

section '.idata' import data readable
library user32,'user32.dll',\
        kernel32,'kernel32.dll',\
        shell32,'shell32.dll',\
        gdi32,'gdi32.dll'
        include 'API\USER32.INC'
        include 'API\KERNEL32.INC'
        include 'API\SHELL32.INC'
        include 'API\GDI32.INC'     
Post 07 Oct 2011, 21:41
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 08 Oct 2011, 20:36
bump.. nobody can help ?..
Post 08 Oct 2011, 20:36
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho 09 Oct 2011, 08:56
this
invoke GetObject,[hBitmap],sizeof.BITMAP,bmpScreen
fails ( return 0 )...

edit
hm,it only fails when I add fileName variable to data section to raplace
raw name in CreateFile function,
strange...
Post 09 Oct 2011, 08:56
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 09 Oct 2011, 18:41
Here's a screen-shot app i made, in fasm.


Description:
Download
Filename: DexShot.zip
Filesize: 292.09 KB
Downloaded: 429 Time(s)

Post 09 Oct 2011, 18:41
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 09 Oct 2011, 20:40
Hi Dex, thanks for that example, it works fine but I have little problem. When trying something like this, it gives me access violation, not valid address at EAX+0x14 ;EAX=0
Code:
section '.data' data readable writeable
input GdiplusStartupInput
token dd ?
encoders_count dd ?
encoders_size dd ?
...
section '.text' code readable executable
        invoke  GdiplusStartup,token,input,NULL
        test    eax,eax
        jnz     exit

        invoke  GdipGetImageEncodersSize,encoders_count,encoders_size; <--- HERE!    

is there any way to do it without encoders ? or to get encoder clsid with different way ? Thank you!

EDIT:
strange, it worked when I tried "input GdiStartupInput 1". But what exactly that 1 does ?
EDIT:
Also, I found this one! Smile http://board.flatassembler.net/topic.php?t=10427
Post 09 Oct 2011, 20:40
View user's profile Send private message Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36 09 May 2016, 08:14
Try this
Code:
include 'win32ax.inc'

.data

struct RGBQUAD
        rgbBlue db ?
        rgbGreen db ?
        rgbRed db ?
        rgbReserved db ?
ends

struct BITMAPINFO
        bmiHeader BITMAPINFOHEADER 40,800,600,1,24,0
        bmiColors RGBQUAD ?
ends

bmpHeader:              ; 54 bytes
        Signature       db 0x42,0x4D,0xC6,0x5F,0x01,00,00,00,00,00,0x36,00,00,00        ; 14 bytes
        bi24BitInfo     BITMAPINFO                                                      ; 40 bytes
pbits   dd ?

memDC   dd ?
winDC   dd ?
hDIB    dd ?
hFile   dd ?
bWritten dd ?

.code

start:
        ; Initialize bitmapinfo
;       mov [bi24BitInfo.bmiHeader.biSize], 40
;       mov [bi24BitInfo.bmiHeader.biWidth], 800
;       mov [bi24BitInfo.bmiHeader.biHeight], 600
;       mov [bi24BitInfo.bmiHeader.biPlanes], 1
;       mov [bi24BitInfo.bmiHeader.biBitCount],24
;       mov [bi24BitInfo.bmiHeader.biCompression], 0

        invoke CreateCompatibleDC, 0
        mov [memDC], eax
        invoke CreateDIBSection, eax, bi24BitInfo, 0, pbits, 0, 0
        mov [hDIB], eax
        invoke SelectObject, [memDC], eax

        invoke GetDC, 0
        mov [winDC],eax
        invoke StretchBlt, [memDC], 0, 0, 800, 600, eax, 0, 0, 1152, 864, 0xCC0020

        invoke CreateFile, 'cap.bmp', GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0
        mov [hFile], eax
        invoke WriteFile, eax, bmpHeader, 54, bWritten, 0
        invoke WriteFile, [hFile], [pbits], 1440000, bWritten, 0        ; 1440000 = 800 * 600 * 3
        invoke CloseHandle, [hFile]

        invoke DeleteDC, [memDC]
        invoke DeleteObject, [hDIB]
        invoke ReleaseDC,HWND_DESKTOP,[winDC]
        invoke ExitProcess, 0

.end start    
Post 09 May 2016, 08:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.