Get more image formats with less overhead

Share your advanced PureBasic knowledge/code with the community.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Don't worry :)

There's only 3 commands:
Grab, resize and ImageOutput.

>> Which command you want to execute, actually?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Which command you want to execute, actually?

If you're talking to me, then I want to be able to use all Image commands
with this tip. ImageWidth(), ImageHeight(), etc.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You'll note that netmaestro's functions actually draw the image retrieved from gdi+ directly onto a PB image.

If you simply replace the two instances of

Code: Select all

ProcedureReturn Retval
with

Code: Select all

ProcedureReturn imagenumber
then you should have what you're after.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Nope, still can't get it. Changed the ProcedureReturn as you said, and I'm
calling it like this:

Code: Select all

f=ImageFromFile(f$)
And then using ImageWidth(f) gives "#Image object not initialized".
I'm not thinking right tonight so maybe I'm missing the obvious?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Let me have a go (must admit that I didn't try it!) :)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Works fine here PB.

With the changes mentoned above :

Code: Select all

Debug ImageWidth(ImageFromFile("open.ico"))
displayed the correct width of the icon I gave it.


**EDIT - yep, works with png's, jpegs,...
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hey,

did you change BOTH ProcedureReturn()'s; one in each of the two relevant procedures ?

:wink:
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I was only using ImageFromFile() so I only changed it there. But, it's now
working (after a quick rewrite of my test app) so I don't know what I was
doing wrong before. :? :lol: Thanks for your help and advice.
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

I missed this too :)

another winner from netmaestro ;)
Paid up PB User !
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

I must learn again to read...

I stopped my reading to the ImageID() without reading the expression between brackets.

2 BP

Excuse me for the lost time... I remember for the next time to prevent me from stay at only one false idea...
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Sorry I have so little time for the forums just now, big thanks to srod for lending support. I'm looking forward to having more time in a couple of weeks.
BERESHEIT
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: Get more image formats with less overhead

Post by Joakim Christiansen »

Any way to get this working with newest PB?
I like logic, hence I dislike humans but love computers.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Get more image formats with less overhead

Post by netmaestro »

Any way to get this working with newest PB?
Using 4.60 RC1 I tested both procedures with a .jpg image and got success. Is there a problem?
BERESHEIT
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: Get more image formats with less overhead

Post by Joakim Christiansen »

netmaestro wrote:
Any way to get this working with newest PB?
Using 4.60 RC1 I tested both procedures with a .jpg image and got success. Is there a problem?
A problem with ImageFromMem it seems!
Try changing CompilerIf 1 to 0 and it will not load the image correctly.

Code: Select all

IncludeFile "gdiplus.decoder.pb"
EnableExplicit

Procedure receiveHTTPMemory(URL$) ;silly one ;P
  Protected *memory
  ReceiveHTTPFile(URL$,GetTemporaryDirectory()+"imgdown")
  If ReadFile(0,GetTemporaryDirectory()+"imgdown")
    *memory = AllocateMemory(Lof(0))
    ReadData(0,*memory,Lof(0))
    CloseFile(0)
  EndIf
  ProcedureReturn *memory
EndProcedure

InitNetwork()
CompilerIf 1 ;1=fromFile, 0=fromMem
  ReceiveHTTPFile("http://umbra.nascom.nasa.gov/images/latest_aia_171.gif","test.gif")
  Define img_image1 = ImageFromFile("test.gif")
CompilerElse
  Define *image1 = receiveHTTPMemory("http://umbra.nascom.nasa.gov/images/latest_aia_171.gif")
  Define img_image1 = ImageFromMem(*image1,MemorySize(*image1))
CompilerEndIf

OpenWindow(0,0,0,600,600,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,600,600,ImageID(img_image1))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
And yes, I've changed your code to ProcedureReturn imagenumber :P
I like logic, hence I dislike humans but love computers.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Get more image formats with less overhead

Post by netmaestro »

Sorry, it seems there was a bug in it from the beginning, but it only shows up if you use AllocateMemory() to save the image in memory as opposed to using a datasection. First post is fixed, please try it now and again, sorry for any inconvenience.

Also, please note that both procs return imagenumber now, so using ImageID() on the return value of both is required. I don't know why I posted a pair of procedures with two different uses for the returns in the first place, that was a mistake.
BERESHEIT
Post Reply