How to save img name day/time ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

How to save img name day/time ?

Post by z1z123 » 15 Sep 2023, 01:42

Code: Select all

#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/blob/master/ahk-v1-imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
loop
{
index := 0, pToken := Gdip_Startup(), pBitmap := Gdip_BitmapFromScreen("927|0|700|620") ; x|y|w|h
Loop
 image := Format(imageDir "C:\Users\admin\Desktop\abc\{:1}.png", ++index)
Until !FileExist(image)
Gdip_SaveBitmapToFile(pBitmap, image), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
sleep 5000
}

how i can named img according to the shooting time ?
ex: 0000.png (00:00am)


z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: How to save img name day/time ?

Post by z1z123 » 15 Sep 2023, 10:22

Code: Select all

#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/blob/master/ahk-v1-imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
SaveDir = C:\Users\admin\Desktop\abc


 pToken := Gdip_Startup(), pBitmap := Gdip_BitmapFromScreen("10|20|307|204") ; x|y|w|h
FormatTime ts,, yyMMdd-HHmmss
 Gdip_SaveBitmapToFile(pBitmap, dir "\image" ts ".png"), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)


Return

Code: Select all

#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/blob/master/ahk-v1-imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
loop
{
index := 0, pToken := Gdip_Startup(), pBitmap := Gdip_BitmapFromScreen("927|0|700|620") ; x|y|w|h
SaveDir = C:\Users\admin\Desktop\abc
Loop
FormatTime ts,, yyMMdd-HHmmss
Until !FileExist(image)
Gdip_SaveBitmapToFile(pBitmap, dir "\image" ts ".png"), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
sleep 5000
}

Code: Select all

#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/blob/master/ahk-v1-imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
loop
{
index := 0, pToken := Gdip_Startup(), pBitmap := Gdip_BitmapFromScreen("927|0|700|620") ; x|y|w|h
SaveDir = C:\Users\admin\Desktop\abc
Loop
FormatTime ts,, yyMMdd-HHmmss
Until !FileExist(image)
Gdip_SaveBitmapToFile(pBitmap, image), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
sleep 5000
}
nothing happen

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: How to save img name day/time ?

Post by mikeyww » 15 Sep 2023, 11:54

Hello,

You cannot just throw lines together and expect everything to work; actually need to define variables that are used, and so on. To understand your script, follow it line by line.

Code: Select all

#Requires AutoHotkey v1.1.33
#Include d:\Q\vis2\lib\Gdip_All.ahk
imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
pToken := Gdip_Startup()
Loop 3 {
 SoundBeep 2500
 pBitmap := Gdip_BitmapFromScreen("927|0|700|620")
 FormatTime ts,, yyMMdd-HHmmss
 Gdip_SaveBitmapToFile(pBitmap, imageDir "\image" ts ".png")
 Sleep 1000
}
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
MsgBox 64, Status, Done!, 1
Run % imageDir
Return

z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: How to save img name day/time ?

Post by z1z123 » 15 Sep 2023, 18:58

i still don't see any img in folder

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: How to save img name day/time ?

Post by mikeyww » 15 Sep 2023, 19:09

In this case, all you need is a short test script.

Code: Select all

#Requires AutoHotkey v1.1.33
#Include d:\Q\vis2\lib\Gdip_All.ahk ; Replace with your Gdip file's path
gdip := "d:\Q\vis2\lib\Gdip_All.ahk"
If !FileExist(gdip) {
 MsgBox 48, Error, % "File not found.`n`n" gdip
 Return
}
image   := A_ScriptDir "\test3.png"
pToken  := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen("0|0|900|900")
FileRecycle % image
Gdip_SaveBitmapToFile(pBitmap, image)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Run % image

z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: How to save img name day/time ?

Post by z1z123 » 15 Sep 2023, 23:23

Code: Select all

#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/blob/master/ahk-v1-imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
SaveDir = C:\Users\admin\Desktop\abc


 pToken := Gdip_Startup(), pBitmap := Gdip_BitmapFromScreen("10|20|307|204") ; x|y|w|h
FormatTime ts,, yyMMdd-HHmmss
 Gdip_SaveBitmapToFile(pBitmap, dir "\image" ts ".png"), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)


Return

Code: Select all

#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation/blob/master/ahk-v1-imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
loop
{
index := 0, pToken := Gdip_Startup(), pBitmap := Gdip_BitmapFromScreen("927|0|700|620") ; x|y|w|h
SaveDir = C:\Users\admin\Desktop\abc
Loop
FormatTime ts,, yyMMdd-HHmmss
Until !FileExist(image)
Gdip_SaveBitmapToFile(pBitmap, dir "\image" ts ".png"), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
sleep 5000
}

Code: Select all

#Requires AutoHotkey v1.1.33
#Include d:\Q\vis2\lib\Gdip_All.ahk
imageDir := A_ScriptDir

F3:: ; F3 = Save screenshot to file
pToken := Gdip_Startup()
Loop 3 {
 SoundBeep 2500
 pBitmap := Gdip_BitmapFromScreen("927|0|700|620")
 FormatTime ts,, yyMMdd-HHmmss
 Gdip_SaveBitmapToFile(pBitmap, imageDir "\image" ts ".png")
 Sleep 1000
}
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
MsgBox 64, Status, Done!, 1
Run % imageDir
Return
I just found out 3 of this work and imgs were saved in C:\, not in folder have .ahk

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: How to save img name day/time ?

Post by mikeyww » 16 Sep 2023, 06:12

These scripts have bugs. Would just try the test script that I posted.

z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: How to save img name day/time ?

Post by z1z123 » 16 Sep 2023, 07:09

i didn't find test3 in computer

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: How to save img name day/time ?

Post by mikeyww » 16 Sep 2023, 07:22

My script will open the image that was saved, or will display an error message if the image is not found.

1. What did you see when running the script?

2. In what directory is your script?

3. What script are you running (post it in a new reply)?

z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: How to save img name day/time ?

Post by z1z123 » 16 Sep 2023, 20:02

Code: Select all

#Requires AutoHotkey v1.1.33
#Include C:\Users\admin\Desktop\abc\Gdip_All.ahk ; Replace with your Gdip file's path
gdip := "C:\Users\admin\Desktop\abc\Gdip_All.ahk"
r::
If !FileExist(gdip) {
 MsgBox 48, Error, % "File not found.`n`n" gdip
 Return
}
image   := A_ScriptDir "\test3.png"
pToken  := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen("0|0|900|900")
FileRecycle % image
Gdip_SaveBitmapToFile(pBitmap, image)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Run % image
file not found, sir
image.png
image.png (17.86 KiB) Viewed 468 times

User avatar
DevWithCoffee
Posts: 54
Joined: 13 Oct 2020, 12:16

Re: How to save img name day/time ?

Post by DevWithCoffee » 16 Sep 2023, 20:14

Would it be something like that?

Code: Select all

#Requires AutoHotkey v1.1.33
#Include <Gdip_All>
if (!pToken := Gdip_Startup())
{
 MsgBox 48, Error, % "File not found.`n`n" gdip
 Return
}

r::
image   := A_ScriptDir "\" A_Hour "" A_Min ".png"
pToken  := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen("0|0|900|900")
FileRecycle % image
Gdip_SaveBitmapToFile(pBitmap, image)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Run % image

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: How to save img name day/time ?

Post by mikeyww » 16 Sep 2023, 20:41

When I provided the test script, I meant that you could run it without any changes other than lines 2 and 3. Just copy and paste the script, and change those two lines to match your Gdip AHK path. Next, run the script.

z1z123
Posts: 42
Joined: 04 Apr 2021, 19:47

Re: How to save img name day/time ?

Post by z1z123 » 16 Sep 2023, 22:35

mikeyww wrote:
16 Sep 2023, 20:41
When I provided the test script, I meant that you could run it without any changes other than lines 2 and 3. Just copy and paste the script, and change those two lines to match your Gdip AHK path. Next, run the script.
then nothing happen, sir
--------------------------------------------------------
DevWithCoffee wrote:
16 Sep 2023, 20:14
Would it be something like that?

Code: Select all

#Requires AutoHotkey v1.1.33
#Include <Gdip_All>
if (!pToken := Gdip_Startup())
{
 MsgBox 48, Error, % "File not found.`n`n" gdip
 Return
}

r::
image   := A_ScriptDir "\" A_Hour "" A_Min ".png"
pToken  := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen("0|0|900|900")
FileRecycle % image
Gdip_SaveBitmapToFile(pBitmap, image)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Run % image
i'm edit it & it work perfect :D

Code: Select all

#Requires AutoHotkey v1.1.33
#Include C:\Users\admin\Desktop\p\Gdip_All.ahk
r::
loop
{
image   := A_ScriptDir "\" A_Hour "" A_Min "" A_Sec ".png"
pToken  := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen("0|0|900|900")
FileRecycle % image
Gdip_SaveBitmapToFile(pBitmap, image)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
sleep 5000
}

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: How to save img name day/time ?

Post by mikeyww » 17 Sep 2023, 06:31

What was the key difference or solution that made the script work?

Post Reply

Return to “Ask for Help (v1)”