Is there any memory stream I can load images from?

BlitzMax Forums/BlitzMax Programming/Is there any memory stream I can load images from?

ziggy(Posted 2009) [#1]
The title says it all, I'm wondering if there's a memory stream on BlitzMax to load images from it.


plash(Posted 2009) [#2]
Huh? Banks maybe?


ziggy(Posted 2009) [#3]
Can you load an image from a bank without passing it on a pixmap?


plash(Posted 2009) [#4]
I think the image loading routine requires a change-through from a pixmap. So in any case, no.

EDIT: Proof:
	Function Load:TImage( url:Object,flags,mr,mg,mb )
		Local pixmap:TPixmap=TPixmap(url)
		If Not pixmap pixmap=LoadPixmap(url)
		If Not pixmap Return
		Local t:TImage=Create( pixmap.width,pixmap.height,1,flags,mr,mg,mb )
		t.SetPixmap 0,pixmap
		Return t
	End Function



ziggy(Posted 2009) [#5]
Yes yo can! I've managed to do it, it was A LOT easier than it seemed thanks to the banks tip. :D
Const FileLocation1:String = "http::www.blitzbasic.com/img/tank_universal.jpg"
Graphics 800, 600
Const BufSize:Int = 1048576	'1 Mega.
Local S:TStream = OpenStream(FileLocation1, True, False)
If s = Null Then
	Print "Stream failed!"
	End
End If
Local Bank:TBank = TBank.Create(BufSize)
Local D:TBankStream = TBankStream.Create(Bank)
Local C:Int = 0
While Not s.Eof()
	d.WriteByte(s.ReadByte())
	C = C + 1
	If C >= Bank.Size() Then Bank.Resize(bank.Size() + BufSize)
Wend
S.Close()
bank.Resize(C)
D.Close()
D:TBankStream = TBankStream.Create(bank)
i = LoadImage(D)
D.Close()


If i = Null Then
	Print "Is Null!"
Else
	Print "Loaded!"
	While Not KeyHit(KEY_ESCAPE)
		Cls
		DrawImage(i, 0, 0)
		Flip
	WEnd
End If
End



plash(Posted 2009) [#6]
It still goes through a pixmap. I assume, by what you just posted, that you initially meant you did not want to have to convert it to a pixmap in your own code. In fact, you never have to.


Brucey(Posted 2009) [#7]
Since loadpixmap supports any kind of TStream, you can therefore pass in any kind of TStream, and it should be able to load it. (like TBankStream, TRamStream, etc)

But as Plash notes (twice), LoadImage always does a LoadPixmap first.


ziggy(Posted 2009) [#8]
ah ok ok, thanks!
I didn't know the existance of TRamStream!!! that's great!!
Now tellme there's also a stringstream somewhere...
:D
Thanks


plash(Posted 2009) [#9]
And this is really how it should be:



ziggy(Posted 2009) [#10]
thanks, that's been super sexy :D I Had no idea you can load an image from a bank, and also had no idea you can load a stream into a bank directly, so all in all, a lot easier than I was doing, and I supose a bit faster.
hehehe
I've never worked *really* with Max Streams and I'm so used to .net ones that I get lost very easilly, so thanks to you all :D


Brucey(Posted 2009) [#11]
Now tellme there's also a stringstream somewhere

There is a brl.textstream, but I don't know if that's what you want?

I've written one before. Can be useful if you want to re-route data into a string that would normally go out to a file or somewhere.