Is there any memory stream I can load images from?
BlitzMax Forums/BlitzMax Programming/Is there any memory stream I can load images from?
| ||
The title says it all, I'm wondering if there's a memory stream on BlitzMax to load images from it. |
| ||
Huh? Banks maybe? |
| ||
Can you load an image from a bank without passing it on a pixmap? |
| ||
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 |
| ||
Yes yo can! I've managed to do it, it was A LOT easier than it seemed thanks to the banks tip. :DConst 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 |
| ||
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. |
| ||
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. |
| ||
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 |
| ||
And this is really how it should be: |
| ||
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 |
| ||
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. |