CatchSprite without IncludeBinary

Just starting out? Need help? Post your questions and find answers here.
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

CatchSprite without IncludeBinary

Post by coma »

Is it possible to put an image in memory using OpenFile and poke, and then to catch it with CatchSprite ?

I put the png data in memory like this :

Code: Select all

If OpenFile(0, "test.png") 
    *MemoryID = AllocateMemory(0, Lof() , 0)
    For i=1 To Lof()
        PokeB(*MemoryID, ReadByte()) 
    Next
    CloseFile(0) 
EndIf
(that I want to do with this is to to load png from a big data file containing all pictures I need)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: CatchSprite without IncludeBinary

Post by GPI »

coma wrote:Is it possible to put an image in memory using OpenFile and poke, and then to catch it with CatchSprite ?

I put the png data in memory like this :

Code: Select all

If OpenFile(0, "test.png") 
    *MemoryID = AllocateMemory(0, Lof() , 0)
    For i=1 To Lof()
        PokeB(*MemoryID, ReadByte()) 
    Next
    CloseFile(0) 
EndIf
(that I want to do with this is to to load png from a big data file containing all pictures I need)
Should function. CatchSprite need a only a Adress.

p.s.: I would take readData()... (or loadsprite)...
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

ok, works fien with this :

If OpenFile(0, "test.png")
*MemoryID = AllocateMemory(0, Lof(), 0)
ReadData(*MemoryID, Lof())
CloseFile(0)
EndIf
CatchSprite(1,*MemoryID , 0)

(but with my pokeb loop, this doesn't work. Anybody know why ?)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

you forget a +i

Code: Select all

If OpenFile(0, "test.png") 
  *MemoryID = AllocateMemory(0, Lof() , 0) 
  For i=1 To Lof() 
    PokeB(*MemoryID+i, ReadByte()) 
  Next 
  CloseFile(0) 
EndIf
but it would be nicer with pointer

Code: Select all

If OpenFile(0, "test.png") 
  *MemoryID = AllocateMemory(0, Lof() , 0) 
  *help.byte
  For i=1 To Lof() 
    *help\b=ReadByte()) :*help+1
  Next 
  CloseFile(0) 
EndIf
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

oh, yes, the +i, of course :)
I'm tired...
thanks a lot.
Post Reply