flat assembler
Message board for the users of flat assembler.
Index
> Windows > Bitmap Screenshots. |
Author |
|
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.
|
|||
03 Oct 2011, 16:28 |
|
cod3b453 03 Oct 2011, 17:11
I did this back in the days of Win98 to make blended windows/menus in VB6
Use: Code: scrDC = CreateDCA("DISPLAY", "", "", 0) Code: SystemParametersInfoA (SPI_GETWORKAREA, 0, rScreen, 0) ... bmTransDC = CreateCompatibleDC(scrDC) bmHTrans = CreateCompatibleBitmap(scrDC, tbSize.X, tbSize.Y) SelectObject(bmTransDC, bmHTrans) Code: BitBlt bmTransDC, 0, 0, tbSize.X, tbSize.Y, scrDC, tbPos.X, tbPos.Y, vbSrcCopy |
|||
03 Oct 2011, 17:11 |
|
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 |
|||
03 Oct 2011, 17:29 |
|
Dex4u 03 Oct 2011, 18:42
Here is a virtual screen app i made, should help you out.
|
|||||||||||
03 Oct 2011, 18:42 |
|
Overflowz 03 Oct 2011, 18:49
Thank you guys! I'm going to study now.
|
|||
03 Oct 2011, 18:49 |
|
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. |
|||
07 Oct 2011, 09:41 |
|
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!
|
|||
07 Oct 2011, 10:40 |
|
dancho 07 Oct 2011, 11:20
|
|||
07 Oct 2011, 11:20 |
|
Overflowz 07 Oct 2011, 12:23
Thank you dancho, that will help me a lot!
|
|||
07 Oct 2011, 12:23 |
|
LocoDelAssembly 07 Oct 2011, 14:41
Quote:
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; |
|||
07 Oct 2011, 14:41 |
|
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' |
|||
07 Oct 2011, 21:41 |
|
Overflowz 08 Oct 2011, 20:36
bump.. nobody can help ?..
|
|||
08 Oct 2011, 20:36 |
|
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... |
|||
09 Oct 2011, 08:56 |
|
Dex4u 09 Oct 2011, 18:41
Here's a screen-shot app i made, in fasm.
|
|||||||||||
09 Oct 2011, 18:41 |
|
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! http://board.flatassembler.net/topic.php?t=10427 |
|||
09 Oct 2011, 20:40 |
|
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 |
|||
09 May 2016, 08:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.