I don't think I'm doing the DllCall correctly for the MagickReadImage method.
https://imagemagick.org/api/magick-image.php#MagickReadImage
it is defined as this in the documentation:
MagickBooleanType MagickReadImage(MagickWand *wand,const char *filename)
and my DllCall looks like this:
DllCall("Core_RL_MagickWand_.dll\MagickReadImage", "Ptr", wand, "char", &filename, "Int")
I should be getting a return value of 1 if the call succeeds, but no matter what I have tried I can only get it to return 0
If anybody could help me understand the correct way to pass the filename, which is I think where I'm going wrong because the exception that it generates is 435 which is an error in reading the file.
https://imagemagick.org/script/exception.php
ImageMagick can be found here https://imagemagick.org/script/download.php#windows
Here is my code so far
Code: Select all
#NoEnv
#SingleInstance Force
SetBatchLines, -1
dir := A_ScriptDir "\"
inFile := "test2b.jpg"
If !(IM := New MagickWandAPI)
ExitApp
Wand := IM.NewMagickWand()
msgbox % "IsMagickWand: " IM.IsMagickWand(Wand)
msgbox % "IsMagickWandInstantiated: " IM.IsMagickWandInstantiated()
Msgbox % "MagickReadImage: " IM.MagickReadImage(Wand, dir infile)
Msgbox % "MagickGetException: " IM.MagickGetException(Wand, Severity)
;Terminate the MagickWand environment.
IM := ""
Return
Class MagickWandAPI {
; ===================================================================================================================
; META FUNCTION __New
; Load and initialize Core_RL_MagickWand_.dll which is supposed to be in the sript's folder.
; Parameters: LibPath - Optional: Absolute path of Core_RL_MagickWand_.dll
; ===================================================================================================================
__New(LibPath := "") {
Static LibMagickWand := A_ScriptDir . "\Core_RL_MagickWand_.dll"
; Do not instantiate instances!
If (This.Base.Base.__Class = "MagickWandAPI") {
MsgBox, 16, MagickWand Error!, You must not instantiate instances of MagickWand!
Return False
}
; Load Core_RL_MagickWand_.dll
If (LibPath)
LibMagickWand := LibPath
If !(MagickWandModule := DllCall("Kernel32.dll\LoadLibrary", "Str", LibMagickWand, "UPtr")) {
If (A_LastError = 126) ; The specified module could not be found
MsgBox, 16, MagickWand Error!, Could not find %LibMagickWand%!
Else {
ErrCode := A_LastError
VarSetCapacity(ErrMsg, 131072, 0) ; Unicode
DllCall("FormatMessage", "UInt", 0x1200, "Ptr", 0, "UInt", ErrCode, "UInt", 0, "Str", ErrMsg, "UInt", 65536, "Ptr", 0)
MsgBox, 16, MagickWand Error!, % "Could not load " . LibMagickWand . "!`n"
. "Error code: " . ErrCode . "`n"
. ErrMsg
}
Return False
}
This.Module := MagickWandModule
This.MagickWandGenesis()
}
; ===================================================================================================================
; META FUNCTION __Delete
; Free ressources
; ===================================================================================================================
__Delete() {
This.MagickWandTerminus()
If (This.Module)
DllCall("Kernel32.dll\FreeLibrary", "Ptr", This.Module)
}
IsMagickWand(wand) {
; https://imagemagick.org/api/magick-wand.php#IsMagickWand
; MagickBooleanType IsMagickWand(const MagickWand *wand)
Return DllCall("Core_RL_MagickWand_.dll\IsMagickWand", "Ptr", Wand, "Int")
}
IsMagickWandInstantiated() {
; https://imagemagick.org/api/magick.php#IsMagickWandInstantiated
; MagickBooleanType IsMagickWandInstantiated(void)
Return DllCall("Core_RL_MagickWand_.dll\IsMagickWandInstantiated", "Int")
}
MagickGetException(Wand, Severity) {
; https://imagemagick.org/api/magick-wand.php#MagickGetException
; char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
DllCall("Core_RL_MagickWand_.dll\MagickGetException", "Ptr", Wand, "Ptr*", Severity)
Return Severity
}
MagickReadImage(wand, filename) {
; https://imagemagick.org/api/magick-image.php#MagickReadImage
; MagickBooleanType MagickReadImage(MagickWand *wand,const char *filename)
OutputDebug, % Filename
Return DllCall("Core_RL_MagickWand_.dll\MagickReadImage", "Ptr", wand, "char", &filename, "Int")
}
MagickWandGenesis() {
; https://imagemagick.org/api/magick-wand.php#MagickWandGenesis
; MagickWandGenesis() initializes the MagickWand environment.
; void MagickWandGenesis(void)
Return DllCall("Core_RL_MagickWand_.dll\MagickWandGenesis", "Int")
}
MagickWandTerminus() {
; https://imagemagick.org/api/magick-wand.php#MagickWandTerminus
; MagickWandTerminus() terminates the MagickWand environment.
; void MagickWandTerminus(void)
Return DllCall("Core_RL_MagickWand_.dll\MagickWandTerminus", "Int")
}
NewMagickWand() {
; https://imagemagick.org/api/magick-wand.php#NewMagickWand
; NewMagickWand() returns a wand required for all other methods in the API.
; A fatal exception is thrown if there is not enough memory to allocate the wand.
; Use DestroyMagickWand() to dispose of the wand when it is no longer needed.
; MagickWand *NewMagickWand(void)
Return DllCall("Core_RL_MagickWand_.dll\NewMagickWand", "Ptr")
}
}
I have spent many hours looking for it in every archive and lost script thread I can find but have had no luck.
https://www.autohotkey.com/board/topic/40797-imagemagick-wrapper-stdlib-r1-2009-05-16/
Thanks!!