thqby / ahk2_lib

MIT License
197 stars 26 forks source link

error on saving image #28

Closed yw4z closed 11 months ago

yw4z commented 11 months ago

first thanks for your effort on this,

i was using this lines to save image on Tariq Porter's gdip for v1

pToken:=Gdip_Startup(),
,Clip:=Gdip_BitmapFromScreen(wX "|" wY "|" wW "|" wH)
FileNm=Screenshot-%A_Now%.png
Gdip_SaveBitmapToFile(Clip,A_WorkingDir "\" FileNm,100)
,Gdip_DisposeImage(Clip)
,Gdip_Shutdown(pToken)

started to upgrade my scripts for v2 and im trying to save image using cgdip with this lines

FileNm:="Screenshot-" A_Now ".png"
,CGdip.Startup()
,CGdip.Bitmap.FromScreen(wX "|" wY "|" wW "|" wH)
,CGdip.Bitmap.Save(A_WorkingDir "\" FileNm,100)
,CGdip.Bitmap.Delete()
,CGdip.Shutdown()

and i get this error

Error: This value of type "Class" has no property named "Ptr".
618: E := DllCall("gdiplus\GdipSaveImageToFile", "Ptr", this, "Ptr", StrPtr(sOutput), "Ptr", pCodec, "Uint", p)

for the comparison you can find whats different from Tariq's

    if (!A_IsUnicode)
    {
        nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
        VarSetCapacity(wOutput, nSize*2)
        DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
        VarSetCapacity(wOutput, -1)
        if !VarSetCapacity(wOutput)
            return -4
        E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
    }
    else
        E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
    return E ? -5 : 0

have a nice day

thqby commented 11 months ago

CGdip.Bitmap.FromScreen(wX "|" wY "|" wW "|" wH).Save(filename)

yw4z commented 11 months ago

thanks for quick reply,

my input for FromScreen > 1010|560|620|460

CGdip.Bitmap.FromScreen(wX "|" wY "|" wW "|" wH).Save(A_WorkingDir "\Screenshot-" A_Now ".png",100)

throws error "invalid pBitmap"

thqby commented 11 months ago

CGdip.Startup() was not called.

yw4z commented 11 months ago

woops thank you :)