Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GDI+ how to get bitmap from certain area of screen?



  • Please log in to reply
8 replies to this topic
BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

Can somebody help me with GDI+? I have this code: https://ahknet.autoh...m/paste/1qu1qpc and error on line 6 or 7. I need to make bitmap from certain area of screen, help?

 

F1::

hwnd := WinExist("A")   ; let's take a screenshot of active window
pToken := Gdip_Startup()


;pBitmap := Gdip_BitmapFromScreen( "hwnd:" hwnd )   ; or    pBitmap := Gdip_BitmapFromHWND(hwnd)
hBitmap := CreateDIBSection( x2-x1, y2-y1)
Gdip_BitmapFromHWND(hwnd)


;Gdip_SaveBitmapToFile(pBitmap, "Full sized image.png") ; save Full sized image


pResizedBitmap := Gdip_ResizeBitmap(pBitmap, 50)   ; resizes to 50% and disposes of pBitmap. Look below for more resizing examples.
Gdip_SaveBitmapToFile(pResizedBitmap, "Resized image.png")  ; save Resized image
Gdip_SetBitmapToClipboard(pResizedBitmap)


Gdip_DisposeImage(pResizedBitmap)
Gdip_Shutdown(pToken)
return

 

 



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

Perhaps this?

F1::
    pToken := Gdip_Startup()
    pBitmap := Gdip_BitmapFromScreen()
    Gdip_SaveBitmapToFile(pBitmap, "Image.png")
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
Return

 

Possibly related: http://www.autohotke...-tools-gdiplus/


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

Masterfocus, thanks for reply, but that is exactly what the original code does. I want to get certein area, e.g. x1=200,y1=200,x2=400,y2=400. Coords I will get from mouse positions so I need only the command to get the part of screen..



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

Have you tried checking what is documented in tic's GDIP.ahk about Gdip_BitmapFromScreen()?

IIRC, it says you should use something like Gdip_BitmapFromScreen("x|y|w|h") to achieve what you want.


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

I have no idea how the function works. I checked arguments and was convinced that it does not uses x,y or w,h arguments. Thanks



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

 For future reference, if a function has a comment block, you should read that for an idea of what it does...

; Function    Gdip_BitmapFromScreen
; Description   Gets a gdi+ bitmap from the screen
;
; Screen    0 = All screens
;                Any numerical value = Just that screen
;                x|y|w|h = Take specific coordinates with a width and height 
...


Join us at the new forum - http://www.ahkscript.org/

 


Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
✓  Best Answer

I found this function in the forum some time ago...

Screenshot(A_ScriptDir "\Screenshot_" A_Now ".png", "300|200|300|200")

; screen: X|Y|W|H
Screenshot(outfile, screen)
{
	pToken := Gdip_Startup()
	pBitmap := Gdip_BitmapFromScreen(screen)
	Gdip_SaveBitmapToFile(pBitmap, outfile, 100)
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken)
}

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

Very nice, thx



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

I have no idea how the function works. I checked arguments and was convinced that it does not uses x,y or w,h arguments. Thanks

lol what did you 'check'