Try this example, it seems to work (File.RawWrite is not same thing than File.Write, Haven't see my error, too tired)
Code: Select all
#NoEnv
#SingleInstance Force
FileDelete, mem.pnm
msgbox % "library:" hModule := DllCall("LoadLibrary", "Str", "FreeImage.dll")
msgbox % "type:" type := DllCall("FreeImage\_FreeImage_GetFileType@8", "AStr", "test.bmp", "Int", 0)
msgbox % "hImage:" hImage := DllCall("FreeImage\_FreeImage_Load@12", "Int", type, "AStr", "test.bmp", "int", 0)
msgbox % "hMemory:" hMemory := DllCall("FreeImage\_FreeImage_OpenMemory@8", "int", 0, "int", 0)
msgbox % "save:" DllCall("FreeImage\_FreeImage_SaveToMemory@16", "int", 0, "int", hImage, "int", hMemory, "int", 0)
mem_buffer := size_in_bytes := 0
; varsetcapacity(mem_buffer, 4, 0), varsetcapacity(size_in_bytes, 4, 0) ; 32bit pointer
MsgBox, % "return:" DllCall("FreeImage\_FreeImage_AcquireMemory@12" , "uint", hMemory, "uint", &mem_buffer, "uint", &size_in_bytes)
MsgBox, % "size:" size := NumGet(size_in_bytes)
MsgBox, % "buffer:" buffer := NumGet(mem_buffer)
file := FileOpen("mem.pnm", "w")
msgbox % "write:" file.RawWrite(buffer+0, size) ; force address
file.Close()
msgbox % "freemem:" DllCall("FreeImage\_FreeImage_CloseMemory@4" , "int", hMemory, "int", 0)
msgbox % "freelib:" DllCall("FreeLibrary", UInt, hModule)
I used a pnm file tag and I checked with a hexadecimal editor (haven't these thing to edit unix picture), each step seems to work, SaveToMemory fail with your tag=7 so check the header (.h or doc) to find tag value.
Else with gdi and a lockbit you can create your own pnm file but that take time and you have to create all specification alone, I already did this for to use with a OCR (but was just a 2 bit depth , black and white), or parse all data with a pure autohotkey solution. Or for example a bin like png2pnm.exe on internet... good luck , do some google search maybe with %whatextIwant%2pnm.exe , some binary can be launched in command and write in in memory with stdin/out, I can't help more sorry...
http://en.wikipedia.org/wiki/Netpbm_format
I don't know what is your goal with pnm file, I found only two old scripts in my personal archive about as ressource (can be intersting for other too, a urbanrivals market bot, and a raw pnm test, that play with pnm value and png layer to discard some problems):
Code: Select all
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
FileDelete, log.txt
FileAppend, % A_Now "`n" , log.txt
Menu, tray, add
Menu, tray, add, log.txt, gotochecklog
menu, tray, Default, log.txt
Menu, Tray, Click, 1
loop
{
Random, rand, 800, 1600
sleep %rand%
FileDelete, A.PNM
FileDelete, B.PNM
FileDelete, C.PNM
FileDelete, D.PNG
FileDelete, E.TXT
;Gui, Add, ActiveX, w980 h640 vWB, Shell.Explorer
;WB.Navigate("URL_LOGIN_cooking")
;Gui, Show
UrlDownloadToFile, http://www.urban-rivals.com/market/?show=0&action=buy&group=all&orderby=asc&sortby=price, data.txt
;UrlDownloadToFile, *0 http://www.urban-rivals.com/market/, data.txt
FileRead, data, data.txt
ID := SubStr(data, p0:=InStr(data, "id_bourse")+11, InStr(data, ",", 0, p0)-p0)
;msgbox % p0 " - " ID
this:="http://dc.ccdn.ur-img.com/price/?id=" ID "&white=0"
UrlDownloadToFile, %this%, D.PNG
RunWait, %comspec% /c png2pnm.exe -n -a A.PNM D.PNG > B.PNM, , Hide
i:=0
Loop, read, A.PNM
if (a_index=2)
C:="P1`n" A_LoopReadLine "`n"
else if (a_index>3)
Loop, parse, A_LoopReadLine, %A_Space%
if (a_loopfield<>"") {
i++
A%i% := a_loopfield
}
j:=0
Loop, read, B.PNM
if a_index>3
Loop, parse, A_LoopReadLine, %A_Space%
if (a_loopfield<>"") {
j++
B%j% := a_loopfield
}
if (i=j) {
loop % i
C .= ((65535 + B%a_index% - A%a_index%) > 32768) ? 0 : 1
}
else
loop % i
{
j1:=a_index*3-2 , j2:=a_index*3-1 , j3:=a_index*3
C .= ((65535 + ((B%j1%+B%j2%+B%j3%)/3) - A%a_index%) > 32768) ? 0 : 1
}
FileAppend, % C, C.PNM
RunWait, %comspec% /c gocr049.exe -m 2 -C 0-9 C.PNM > E.TXT , , Hide
FileRead, E, E.TXT
StringReplace, E, E, `r`n, , All
StringReplace, E, E, %a_space%, , All
if E is integer
{
if (E<121) {
UrlDownloadToFile, http://www.urban-rivals.com/ajax/market/?action=purchase&id_bourse=%ID%, r.txt
FileRead, r, r.txt
FileAppend, % A_Hour ":" A_Min ":" A_Sec " " r " " E "`n", log.txt
TrayTip, %E%, %r%, 5, 17
error := SubStr(r, InStr(r, ":")+1, 1)
if (error = "-") {
SoundBeep, 440, 1000
exitapp
}
}
}
else
{
FileMove, C.PNM, error\%A_Now%.pnm
FileMove, D.PNG, error\%A_Now%.png
FileAppend, % A_Hour ":" A_Min ":" A_Sec " ERROR " E " " A_Now "`n", log.txt
TrayTip, %E%, ERROR %A_Now%, 5, 17
}
}
return
gotochecklog:
Run, log.txt
return
esc::
exitapp
; http://www.urban-rivals.com/ajax/market/?action=cancel_sale&ids_persos_joueur=239550383&ids_bourse=191619660
; http://www.urban-rivals.com/ajax/market/?action=purchase&id_bourse=191631494
; gocr049.exe -m 130 db119.pnm ; set db
; gocr049.exe -m 2 db120.pnm ; use db
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;FileRead, data, data.txt
;name:=SubStr(data, p1:=InStr(data, ">", 0, InStr(data, "<div class=""character"">")+23)+1, InStr(data, "<", 0, p1)-p1)
;msgbox % "*" name "*"
FileDelete, result.pgm
i:=0
Loop, read, 1.PGM
if (a_index=2)
{
StringSplit, param, A_LoopReadLine, %A_Space%
C:="P5 " param1+1 " " param2 " 255 "
}
else if (a_index>3)
Loop, parse, A_LoopReadLine, %A_Space%
if (a_loopfield<>"") {
i++
A%i% := a_loopfield
}
j:=0
Loop, read, 2.PNM
if a_index>3
Loop, parse, A_LoopReadLine, %A_Space%
if (a_loopfield<>"") {
j++
B%j% := a_loopfield
}
if (i=j) {
loop % i
{
if (Mod(a_index, param1)=8)
C .= Chr(255)
C .= Chr(Floor((65535 + B%a_index% - A%a_index%)/258)+1)
}
}
else
loop % i
{
j1:=a_index*3-2 , j2:=a_index*3-1 , j3:=a_index*3
C .= Chr(Floor((65535 + ((B%j1%+B%j2%+B%j3%)/3) - A%a_index%)/258)+1)
}
FileAppend, % C, *result.pgm