AutoHotkey Community

It is currently May 27th, 2012, 11:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 181 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13  Next
Author Message
 Post subject:
PostPosted: September 29th, 2011, 10:08 am 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Is there anyway to capture a rectangle of a window that isnt active, or visible?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2011, 6:37 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
You can use gdip library to get it done.


Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

SetTitleMatchMode, 2
;#include gdip.ahk   ;http://www.autohotkey.com/forum/topic32238.html

wintitle=IrfanView

x=50
y=50
w=300
h=300

If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}

WinGet, hwnd,ID,%wintitle%

pBitmap:=Gdip_BitmapFromHWND(hwnd)
pBitmap_area:=Gdip_CloneBitmapArea(pBitmap, x, y, w, h)

Gdip_SetBitmapToClipboard(pBitmap_area)          ;set image to clipboard
Gdip_SaveBitmapToFile(pBitmap_area, "area.png")  ;saves image to file
 
Gdip_DisposeImage(pBitmap_area)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2011, 9:29 am 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Thank you very much.

I will give this a try!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2011, 7:52 pm 
It works fine on its own, but when I try and incorporate into another script via a function, its not creating the image file.

Code:
GetNotepad(win)
{
   Global
   SetTitleMatchMode, 2

   x=5
   y=22
   w=20
   h=20

   WinGetTitle, hwndB, ahk_id %win%

   If !pToken := Gdip_Startup()
   {
      MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
      ExitApp
   }

   pBitmap:=Gdip_BitmapFromHWND(hwndB)
   pBitmap_area:=Gdip_CloneBitmapArea(pBitmap, x, y, w, h)

   Gdip_SetBitmapToClipboard(pBitmap_area)          ;set image to clipboard
   Gdip_SaveBitmapToFile(pBitmap_area, "c:\area.png")  ;saves image to file
 
   Gdip_DisposeImage(pBitmap_area)
   Gdip_DisposeImage(pBitmap)
   Gdip_Shutdown(pToken)
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2011, 8:55 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Code:
WinGetTitle, hwndB, ahk_id %win%
You are storing window's title in hwndB variable and than passing it as hwnd in pBitmap:=Gdip_BitmapFromHWND(hwndB)
I guess you want to delete line
WinGetTitle, hwndB, ahk_id %win%
and specify
pBitmap:=Gdip_BitmapFromHWND(win)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: no output
PostPosted: October 20th, 2011, 12:54 pm 
Offline

Joined: October 11th, 2011, 2:12 pm
Posts: 1
Location: Here
I am running xp sp2 and ahk_l Seans script from the OP runs and I get no result whatsoever. The script is unchanged. Does anyone have a clue what might be wrong? Is there something to edit in the script before it will produce an image file at all?

EDIT:::

I see this:
It's only a function, so you have to call it.
Add this line
Code:
CaptureScreen(0, 1)
at the beginning of ScreenCapture.ahk script to test it.
It saves entire desktop as screen.bmp in the script folder.

So I added this to top of script:
CaptureScreen(0, 1)

now i see this in message window ErrorStdOut

I'll keep reading ; )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2011, 11:46 pm 
Offline

Joined: May 25th, 2010, 8:26 am
Posts: 22
So I read through all the stuff here and have come to realize it doesnt work with AHK_L so I was wondering if anyone did manage to get it working with it or not? I am not familair with converting one script from one style to another, all my scripts I had written in AHK worked just fine in AHK_L without modification.

So if someone has a copy that works with AHK_L that would be great. Or even an alternative I simply need to screenshot specific coordinates (or screenshot and then only extract those coordinates) and save it to a file.

Thanks in advance.

_________________
Computerspazzz The Technowizard
The Wizard Is In!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2011, 1:03 am 
Offline

Joined: February 16th, 2010, 8:01 am
Posts: 800
Location: SciTE
The GDI+ libraryby tic is a better option for you I think. It can do the same things, depending on what you want to get done, you just need to look at the functions that are already written.

The following script is written assuming you have tic's GDI+ library in your standard lib folder for AHK.

Take a look at this script (Win+S to store a screenshot on clipboard):

Code:
#s::SStoClip() ; Executes the Screenshot to clip function



ToolTipOff:
ToolTip
return

; Defines area then takes screenshot and stores it on the clipboard
SStoClip(){
Global OverlayFlag
DefineBox(TLX, TLY, BLX, BLY, BW, BH)
If (OverlayFlag = "Error")
{
   ToolTip, Error: Screencap exited
   SetTimer, ToolTipOff, -3000
   return
}
ScreenPass := TLX "|" TLY "|" BW "|" BH
if (!pToken:=Gdip_Startup()) {
      msgbox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
      ExitApp
   }
MypBitmap := Gdip_BitmapFromScreen(ScreenPass)
Gdip_SetBitmapToClipboard(MypBitmap)
DeleteObject(MypBitmap)
ToolTip, Screenshot stored on clipboard.
SetTimer, ToolTipOff, -3000
return
}

; User defined box and the dimensions
DefineBox(ByRef TopLeftX, ByRef TopLeftY, ByRef BottomRightX, ByRef BottomRightY, ByRef BoxWidth, ByRef BoxHeight) ;This function needs to return the coords of the top left corner x/y  of the square and bottom right corner x/y of the square
{
CoordMode, ToolTip, Screen
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
WS_EX_LAYERED:=0x00080000 ;positioned here for ease of GDI+ use
WS_EX_NOACTIVATE:=0x08000000
{
    ;generate GUI to cover the active window so you don't play with things in it while you select your box.
   Gui, 2: +LastFound -Caption +AlwaysOnTop
   Gui, 2: Color, White
   Gui, 2: Show, Hide
   WinSet, Transparent, 100
   Gui, 2: Show, NA x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%
   Global OverlayFlag
   OverlayFlag := 1
   
   
   ;Wait for the left mouse button to start the GDI+
   KeyWait, LButton, D
   if (!pToken:=Gdip_Startup()) {
      msgbox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
      ExitApp
   }
;Generate the GDI+
Gui, 3: +LastFound -Caption +AlwaysOnTop +E%WS_EX_LAYERED% +E%WS_EX_NOACTIVATE%
Gui, 3: Show, NA
Width:=A_ScreenWidth
Height:=A_ScreenHeight
   MouseGetPos, MX, MY
   MX := MX-1
   MY := MY-1

Loop {
   MouseGetPos, NewMX, NewMY
   NewMX := NewMX-1
   NewMY := NewMY-1
   XWidth := (NewMX-MX)
   YHeight := (NewMY-MY)

hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pPen := Gdip_CreatePen(0x990000ff, 2)
Gdip_DrawRectangle(G, pPen, MX, MY, XWidth, YHeight)
Gdip_DeletePen(pPen)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
if (GetKeyState("LButton", "P") = 0)
   {
      Break
   }
}
   Gui, 2:Destroy
   Gui, 3:Destroy
   
   If (OverlayFlag != "Error")
   OverlayFlag := 0
   
   TopLeftX:=MX
   TopLeftY:=MY
   BottomRightX:=NewMX
   BottomRightY:=NewMY
   BoxWidth := NewMX-MX
   BoxHeight := NewMY-MY
}
CoordMode, ToolTip, Relative
CoordMode, Pixel, Relative
CoordMode, Mouse, Relative
return
}

_________________
AutoHotkey Basic - Windows 7
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2011, 5:29 am 
Offline

Joined: May 25th, 2010, 8:26 am
Posts: 22
Nice! Thank you very much. This is an awesome tool for the kinds of things I do anyway, will save me allot of extra steps using IrfanView I think lol... but yes I believe it will also allow me to deconstruct it to serve my purposes. Thanks again!

_________________
Computerspazzz The Technowizard
The Wizard Is In!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: You're welcome.
PostPosted: March 1st, 2012, 1:38 am 
Offline

Joined: November 28th, 2008, 11:42 am
Posts: 7
Location: Dallas, Tx
First draft of a practical app for this. Thanks so much, Sean. Your functions are exactly what I needed!

PhotoCapture (uncompiled):
http://www.putlocker.com/file/1A4D839639781FDA

It's pretty straight-forward, but any questions, let me know.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: AHK_L support?
PostPosted: March 19th, 2012, 12:15 am 
Offline

Joined: March 19th, 2012, 12:13 am
Posts: 1
computerspazzz wrote:
So I read through all the stuff here and have come to realize it doesnt work with AHK_L so I was wondering if anyone did manage to get it working with it or not? I am not familair with converting one script from one style to another, all my scripts I had written in AHK worked just fine in AHK_L without modification.

So if someone has a copy that works with AHK_L that would be great. Or even an alternative I simply need to screenshot specific coordinates (or screenshot and then only extract those coordinates) and save it to a file.


Check: http://www.autohotkey.com/forum/topic18146-132.html


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2012, 2:40 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
It will be easy with the Gdip library by tic. http://v.gd/gdip_

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 9th, 2012, 9:56 am 
Offline

Joined: November 28th, 2008, 11:42 am
Posts: 7
Location: Dallas, Tx
Oh yea, I realized I was an idiot and modified my script to simply click the top left and bottom right corners of the image to capture, using the shield gui to prevent triggering any page scripts. If anyone wants the updated version let me know.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 7th, 2012, 10:14 am 
Offline

Joined: June 30th, 2009, 12:14 am
Posts: 20
where does one get the gui.dll that this script requires?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 11th, 2012, 11:11 pm 
Offline

Joined: May 11th, 2012, 11:05 pm
Posts: 6
I'm having a lot of difficulty getting this to run. I've #included the script, and call screen capture, but nothing happens. No file is created, no messages, nothing. Before I ever tried to run the script, I downloaded gdiplus.dll from dll-files.com and ran their software. I'm thinking maybe this has messed something up?

When I searched for gdiplus.dll, I found several copies: one is C:\Windows\SysWOW64 and several in C:\Windows\winsxs. A friend of mine never took these steps, and his copy of the script is running fine. So, then, what will I need to do to get this running on my own machine?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 181 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: iDrug and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group