Page 2 of 2
Posted: Thu Mar 31, 2005 10:01 pm
by Shannara
Thanks for replying. Please note the code works perfectly when the application is compiled, as noted by myself and NoahPhense. It does not work when debugging the application.
Posted: Thu Mar 31, 2005 10:44 pm
by NoahPhense
Shannara wrote:Thanks for replying. Please note the code works perfectly when the application is compiled, as noted by myself and NoahPhense. It does not work when debugging the application.
Wouldn't you think that is because the exe when ran from the IDE is
actually inside the Compiler directory?
- np
Posted: Thu Mar 31, 2005 10:58 pm
by Shannara
Wait .... say that again? Actually I do not know if that would make much of a difference, only because I usually put the full path of the library + library file name, when calling the library and same for the image.
And it returns a non-zero number which means it should be valid, but it cannot be used. hrm.
Posted: Fri Apr 01, 2005 2:40 am
by NoahPhense
Shannara wrote:Wait .... say that again? Actually I do not know if that would make much of a difference, only because I usually put the full path of the library + library file name, when calling the library and same for the image.
And it returns a non-zero number which means it should be valid, but it cannot be used. hrm.
Wierd because mine works from inside the IDE. I'm pointing to the dll
fully and my include..
Code: Select all
Declare ChangeImage(pngFilename.s)
Declare.s GetFile()
IncludeFile "C:\source\purebasic\Projects\imageDLL.Example\include.pb"
#dll = 1
Toggle = 0
Global ff_PNG.l ; The address in memory of the function from the library.
; (for CallFunctionFast)
; // letsgotothelibrary // ------------------------------------------ //
If OpenLibrary(#dll, "C:\source\purebasic\Projects\imageDLL.Example\ImageProcessing.dll")
; lets see if its a real function
ff_PNG.l = IsFunction(#dll, "LoadPNG")
Else
MessageBox_(0, "could not locate dll", "DLL ERROR", #MB_SYSTEMMODAL)
End
EndIf
- np
*edit*
Also I noticed that catchimage would be ok, if you images were
included binaries as shown in the manual. But it is not needed at
all when loading from disk. LoadImage, which is in the dll is
doing a fine job of assigning a new ImageID ..
Code: Select all
ProcedureDLL.l LoadPNG(Filename.s)
UsePNGImageDecoder()
result = LoadImage(#PB_Any, Filename)
ResizeImage(result, 240,200) ; make it fit
ProcedureReturn result
EndProcedure
Posted: Fri Apr 01, 2005 3:16 am
by Shannara
Hmm, here is what I have where catchimage shows 0.
ImageLib.pb (compile into dll)
Code: Select all
ProcedureDLL.l LoadPicture(FileName.s)
;This will load a PNG picture and soon do manipulation
UseJPEGImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()
UsePNGImageDecoder()
GM = LoadImage(#PB_Any,FileName)
ProcedureReturn GM
EndProcedure
Test.pb (run w/ Debugger)
Code: Select all
Global ff_Picture.l
Global myLIB.l
Global rt1.l
Global bgMenu.l
myLIB = OpenLibrary(#PB_Any, "C:\Projects\ImageLib\ImageLib.dll")
ff_Picture = IsFunction(myLIB, "LoadPicture")
rt1 = CallFunctionFast(ff_Picture, "C:\Projects\ImageLib\bgMenu.png")
Debug "rt1: " + Str(rt1) ; <-- This should be higher then 0, and it is!
bgMenu = CatchImage(#PB_Any, rt1)
Debug "bgMenu: " + Str(bgMenu) ; <-- This should be higher then 0, but it is not!
CloseLibrary(myLIB)
End
Will need to change the paths to match your system

The files are zipped up and linked below for your viewing pleasure

Included is the png image
http://www.teenyhost.com/ImageLib.zip
(added): I see what you mean concerning CatchImage. However, the manual state any memory address. For some reason I thought the return was that and/or the handle .. heh. I think that may explain the 0 result there, but ...
How would I go about copying that image handle into a new image? That way, I can close out the library and not worry about the image disappearing?
Posted: Fri Apr 01, 2005 5:02 am
by NoahPhense
It says in the manual that catchimage is useful for embedded images.
LoadImage .. which is what you are using in your DLL is already handling
the image.
there is nothing to catch, as it is not REALLY in memory after being LoadImaged ..
My example shows an embedded image, which when the exe is launched,
puts the image(s) into memory, where I will then "catch" it..
If I was loading a file from disk, with LoadImage, then I am mearly
grabbing the handle. That is why you see nothing in the manual about
free'ing memory under LoadImage, only CatchImage...
So I then have to say that you are using CatchImage in the wrong
context.
Please note in my example, there is no LoadImage.. why, because im
not grabbing files from the disk.. but from memory.
image.sound.rar
- np
ps - ive included the mutex lib.. if you dont want/need it.. just remove the
two mutex lines from the code..
Posted: Fri Apr 01, 2005 11:56 am
by tinman
Shannara wrote:How would I go about copying that image handle into a new image? That way, I can close out the library and not worry about the image disappearing?
Have you tried:
bgMenu = CatchImage(#PB_Any, UseImage(rt1))
Or is it ImageID() that gets the image handle? I can't remember.
Posted: Fri Apr 01, 2005 2:43 pm
by NoahPhense
You already have the new image ID returned
from the dll and stored it in, rt1.. now all that
is needed is:
- np
Posted: Fri Apr 01, 2005 8:01 pm
by Shannara
I'll have to wait till I get home and try this. So I can easily do the copy there, and close out the dll and still use Bgmenu? that rules big time!
Posted: Fri Apr 01, 2005 10:22 pm
by Shannara
No go, both the rt1 and bgmenu value cannot be used for brushes or anything whether the library is still open or closed .. bah, thats ok then, I'll see how much UPX can compress the exe with these decoders in it... this have been spanning for days with no resolve, bah!