Added to the code above cases if second monitor is on the left, top or bottom of the first one. Monitors should not be off set i.e.:
- top borders of both monitors should be in one line (for sec. mon. on left or right)
- left borders of both monitors should be in one line (for sec. mon. on top or bottom)
Screen clipping
Re: Screen clipping
Unfortunately, I couldn't make it work. Do you mean the first If with "the code above"?Added to the code above cases if second monitor is on the left, top or bottom of the first one.
This is my monitors' layout. My second monitor is rotated 90 degree so I tried swapping its width and height as well but it doesn't work. It is still offset.
- Attachments
-
- image.png (57.54 KiB) Viewed 2854 times
Last edited by anhnha on 28 Dec 2022, 04:40, edited 2 times in total.
Re: Screen clipping
The second if is for your layout, but you can copy all of them, it shouldn't affect the result.
Show your code!
Re: Screen clipping
I added to this function as mentioned in previous post.
I also tried to swap the width and height of the second monitor but it doesn't work as well.
I also tried to swap the width and height of the second monitor but it doesn't work as well.
Code: Select all
dip_BitmapFromScreen(Screen=0, Raster="")
{
if (Screen = 0)
{
Sysget, x, 76
Sysget, y, 77
Sysget, w, 78
Sysget, h, 79
}
else if (SubStr(Screen, 1, 5) = "hwnd:")
{
Screen := SubStr(Screen, 6)
if !WinExist( "ahk_id " Screen)
return -2
WinGetPos,,, w, h, ahk_id %Screen%
x := y := 0
hhdc := GetDCEx(Screen, 3)
}
else if (Screen&1 != "")
{
Sysget, M, Monitor, %Screen%
x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
}
else
{
StringSplit, S, Screen, |
x := S1, y := S2, w := S3, h := S4
}
if (x = "") || (y = "") || (w = "") || (h = "")
return -1
firstMonScale := 150
secondMonScale:= 100
firstMonWidth := 3480
firstMonHight := 2160
secondMonWidth:= 1920
secondMonHight:= 1080
if (x>firstMonWidth) {
x:= round(((x-firstMonWidth)/(firstMonScale/secondMonScale))+firstMonWidth)
y:= round(y/(firstMonScale/secondMonScale))
}
if (x<0 || y<0) {
x:= round(x/(firstMonScale/secondMonScale))
y:= round(y/(firstMonScale/secondMonScale))
}
if (y>firstMonHight) {
x:= round(x/(firstMonScale/secondMonScale))
y:= round(((y-firstMonHight)/(firstMonScale/secondMonScale))+firstMonHight)
}
chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
ReleaseDC(hhdc)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
return pBitmap
}
Re: Screen clipping
I edited the code above again. Try it and if it doesn't work make PrintScreen (after capturing) and post it here.
Re: Screen clipping
Thanks for your patience!
As much as I can estimate from your gif, scaling of the dimensions is correct especially x and y coordinats, but capture itself is too small so we have to enlarge it. I'll try to do it tomorrow!
bye for now!
As much as I can estimate from your gif, scaling of the dimensions is correct especially x and y coordinats, but capture itself is too small so we have to enlarge it. I'll try to do it tomorrow!
bye for now!
Re: Screen clipping
I should be thanking you instead.
The x and y coordinates are correct but the region is expanding to the left and bottom so the capture region is larger than needed.
I tried it for both small and large capture regions and they're expanding the same way.
The x and y coordinates are correct but the region is expanding to the left and bottom so the capture region is larger than needed.
I tried it for both small and large capture regions and they're expanding the same way.
Re: Screen clipping
From now on this cannot be fixed by coordinats. It is internal Gdi+ issue.
Re: Screen clipping
I edited the code above again. Try it and if it doesn't work pleas make gif again and post it here.
Re: Screen clipping
The capture region was bigger than drawn region last time but now it's smaller.
https://gifyu.com/image/SvS7T
https://gifyu.com/image/SvS7T
Re: Screen clipping
Try to replace hbm := CreateDIBSection(w, h, chdc) with hbm := CreateDIBSection(ws, hs, chdc).
Re: Screen clipping
Good news and thanks we finally did it, although partially hardcoded (first monitor size & scales)!
P.s.: It would be interesting to see the result if capturing rectangle would extend through border of both monitors!
So, yes it should work under listed conditions, however not tested (that's why it took so long - didn't have testing opportunity). Remains to test if it would work for e.g.: firstMonScale:= 150, secondMonScale:= 200rommmcek wrote: ↑27 Dec 2022, 02:17Added to the code above cases if second monitor is on the left, top or bottom of the first one. Monitors should not be off set i.e.:
- top borders of both monitors should be in one horizontal line (for sec. mon. on left or right)
- left borders of both monitors should be in one vertical line (for sec. mon. on top or bottom)
P.s.: It would be interesting to see the result if capturing rectangle would extend through border of both monitors!
Re: Screen clipping
I tried firstMonScale:= 150, secondMonScale:= 100 and firstMonScale:= 150, secondMonScale:= 125 and both worked well.Remains to test if it would work for e.g.: firstMonScale:= 150, secondMonScale:= 200
I don't see option to set to 200 in my monitor setting.
It does but doesn't seem to work properly in my monitors as I can't draw rectagle region across both monitors with same height.P.s.: It would be interesting to see the result if capturing rectangle would extend through border of both monitors!
Re: Screen clipping
Never mind, if somebody encounters problem will post it or even fix it!
Yeh, I can imagine. To fix it would be to much hassle and little gain.
bye and Happy New Year!
Re: Screen clipping
Thanks for the help. I was happy that setting both monitors with the same scale works but now I can set it any scale I want.
Re: Screen clipping
Thanks for this!! I have condensed your code a bit to make the hotkey section more readable and only use a single hotkey!!:
Code: Select all
; use the following code instead of SpeedMaster's code
; insert this line inside the #IfWinActive section
^b::(Btoggle:= !Btoggle) ? SpeedMaster_RemoveBorders() : SpeedMaster_RestoreAllClipWinsBorders() ; fancy toggle to turn off and on the clipping's border
; insert the following functions somewhere in the function section
SpeedMaster_RemoveBorders() {
WinGet, Hwnd, ID, A
WinGet, Style, Style, ahk_id %Hwnd%
if (Style & 0x2000)
{
WinSet, Style, -0x2000, A
WinSet, Region, , A
}
else
{
WinGetPos, X, Y, W, H, ahk_id %Hwnd%
W -= 6, H -= 6
WinSet, Style, +0x2000, A
WinSet, Region, 3-3 W%W% H%H%, A
}
} ; contributed by SpeedMaster @ https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=180#p430673
SpeedMaster_RestoreAllClipWinsBorders() {
MaxGuis:= SCW_Reg("MaxGuis"), StartAfter:= SCW_Reg("StartAfter")
Loop, %MaxGuis%
{
StartAfter++
Gui %StartAfter%: +lastfound
WinSet, Region,
}
} ; contributed by SpeedMaster @ https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=180#p430673
Re: Screen clipping
Hi @anhnha, have the same issue you had... Try to follow all you posts but impossible, I am messed up. Could you summarize what you exactly change in your code ?
THanks a lot for help.
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: Bing [Bot], yzqiang and 79 guests