Update: I changed the subject so people recognize its not only yet-another-screenshot tool. but a way to save the screen fast in all formats supported by gdiplus (which is already installed in newer windows versions). as its gdiplus its quite fast.
Update: Now you can make a screenshot with win-c for (capture thumb) and win-v for (capture fullscreen). it also creates two folders for your images.
Finally i managed to create Screenshots with AHK without external DLLs or other *cheating*. its pure AHK and not using pixel by pixel reading.
all formats where gdiplus has an handler (bmp, jpg, png, tiff..) are supported.
to keep it simple it only works with png now.
for writing the png/bmp i used the code from PhiLho. (see more details there to use other formats and parameters, its easy to use it also for gif,jpg,bmp, tiff etc. )
http://www.autohotke...pic.php?t=11860
i copied the 3 needed includes into one file so its easier to use.
see my other scripts with
ScreenMagnifier:
http://www.autohotke...pic.php?t=11700
or
LiveWindows:
http://www.autohotke...pic.php?t=11588
to see how you can play around with BitBlt and StrechBlt to modify the image.
there is also no cheating with hitting printkey and clipboard. etc.
this is honest copy DC to File
the missing link was "GdipCreateBitmapFromHBITMAP"
and learning that UIntP, is used for ByVal. This means the dllcall returns something "into" this variable.
Now i can get rid of iview.exe if i want
The speed should be anayzed, perhaps this bin2hex stuff copies every pixel in memory?
press win-x to exit
press win-c to save current desktop as thumbnail
press win-v to save current desktop 1:1
filename is automatic in the moment containing date+time.png
Version 0.1 : initial
Version 0.2 : bugfix of landvermesser, always gdistop (memory leak)
#Include GDIPlusHelper.ahk
; see: http://www.autohotkey.com/forum/viewtopic.php?t=11860 for orignal
OnExit, handle_exit
main:
FileCreateDir, screens
FileCreateDir, thumbs
WinGet, hw_frame, id, "Program Manager" ; Desktop ?
hdc_frame := DllCall( "GetDC", "uint", hw_frame )
hdc_frame_full := DllCall( "GetDC", "uint", hw_frame )
counter:=0 ; thumbnails
counter_f:=0 ; fullscreens
thumb_w:= 200
thumb_h:= ceil( thumb_w * A_ScreenHeight / A_ScreenWidth ) ; keep screenratio
use_antialize := 1
; buffer
hdc_buffer := DllCall( "gdi32.dll\CreateCompatibleDC" , "uint", hdc_frame )
hbm_buffer := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hdc_frame, "int", thumb_w, "int", thumb_h )
r := DllCall( "gdi32.dll\SelectObject" , "uint", hdc_buffer, "uint", hbm_buffer )
hdc_buffer_full := DllCall( "gdi32.dll\CreateCompatibleDC" , "uint", hdc_frame_full )
hbm_buffer_full := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hdc_frame_full, "int", A_ScreenWidth, "int", A_ScreenHeight )
r_full := DllCall( "gdi32.dll\SelectObject" , "uint", hdc_buffer_full, "uint", hbm_buffer_full )
; comment this line for speed but less quality
if use_antialize = 1
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_buffer, "int", 4 ) ; Halftone better quality with stretch
return
#c::
SaveImage:
counter := counter +1
FormatTime, myTime, , yyyyMMdd_hhmmss
fileNameDestP = thumbs\T_%myTime%_%counter%_%thumb_w%x%thumb_h%.png
If (GDIplus_Start() != 0)
Goto GDIplusError
; Copy BMP from DC
DllCall( "gdi32.dll\StretchBlt"
, "uint", hdc_buffer, "int", 0, "int", 0, "int", thumb_w, "int", thumb_h
, "uint", hdc_frame, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight, "uint", 0x00CC0020 )
DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer, uint, 0, uintp, bitmap )
; Save to PNG
If (GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_png) != 0)
Goto GDIplusError
noParams = NONE
If (GDIplus_SaveImage(bitmap, fileNameDestP, pngEncoder, noParams) != 0)
Goto GDIplusError
Gosub GDIplusStop
Return
#v::
SaveImage_Full:
counter_f := counter_f +1
FormatTime, myTime, , yyyyMMdd_hhmmss
fileNameDestP = screens\S_%myTime%_%counter_f%_%A_ScreenWidth%x%A_ScreenHeight%.png
If (GDIplus_Start() != 0)
Goto GDIplusError
; Copy BMP from DC
DllCall( "gdi32.dll\BitBlt"
, "uint", hdc_buffer_full, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight
, "uint", hdc_frame_full, "int", 0, "int", 0, "uint", 0x00CC0020 )
DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer_full, uint, 0, uintp, bitmap )
; Save to PNG
If (GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_png) != 0)
Goto GDIplusError
noParams = NONE
If (GDIplus_SaveImage(bitmap, fileNameDestP, pngEncoder, noParams) != 0)
Goto GDIplusError
Gosub GDIplusStop
Return
GDIplusError:
GDIplusStop:
If (#GDIplus_lastError != "")
MsgBox 16, GDIplus Test, Error in %#GDIplus_lastError%
GDIplus_Stop()
Return
#x::
handle_exit:
DllCall( "gdi32.dll\DeleteObject", "uint", hbm_buffer )
DllCall( "gdi32.dll\DeleteDC" , "uint", hdc_frame )
DllCall( "gdi32.dll\DeleteDC" , "uint", hdc_buffer )
ExitApp
you need to have
http://www.holomind....IPlusHelper.ahk (includes 29kb)
in the same directory.
For quick downloads:
http://www.holomind..../screenshot.ahk (src 2kb)
http://www.holomind..../screenshot.exe (compiled 193kb)
variation with thumbnails:
http://www.holomind....nshot_thumb.ahk (src 2kb)




