123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|736|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Curiosity has overtaken me

Page : 1 2 Next
Prev
Sat, 28 Apr 2007, 06:35
Blitz3Dman
I've been wondering this for a mighty long time and I figure I ought to ask eventually.

Is it possible, using Blitz, to read a wed-hosted image and use it in a program?

It may sound a little far fetched, but if I can read the image data online, I know how to do the rest.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 06:44
bram32
You could use the BlitzGet function. I tried it once, however I don't remember which version. So if this version doesn't work, try searching for 'blitzget' in google.
www.blitzbasic.com/codearcs/codearcs.php?code=24
It downloads the data first, after that, you can open it.
Sat, 28 Apr 2007, 06:44
oscar
it is... I'll get my code for it... I put it into my BHTML program a while ago...

Basically you open the file using the network functions.. and save the stream (minus teh httpd bits) as a file with the apporriate extension (you can delete or overwrite the file as needed)

(stand by for edit with da codez)
Sat, 28 Apr 2007, 09:52
JL235
You could also make your own image loading routine. You'd read the data from the stream, make a new image buffer, and then draw the data to the buffer.

I've made my own code for reading and loading .bmps a few times. But other images formats are a lot harder because of the compression they use (especially .jpegs).

One time I wanted to load and store image data into an array. Reading the image straight as a file, rather then loading as an image and reading from an image buffer, was phenominally faster.
Sat, 28 Apr 2007, 10:35
Blitz3Dman
Erm, oscar? You posted that a few hours ago...

I know how to do the making the image bit, it's just I don't know how to get the data in the first place

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 10:41
flying_cucco
Blitz includes commands for working with TCP streams so you can download files easily.



|edit| minor fixes |edit|
Sat, 28 Apr 2007, 10:48
Blitz3Dman
Unfortunately, I don't know what the server bit of it is.. the one time I tried to work with internet stuff, well let's just say I made a mess of things, especially my brain.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 10:55
flying_cucco
This function basically asks a webserver for a file, and dumps it to a local file, just like your webbrowser would if you downloaded it there.

server$ = the server you are connecting to, ie "www.google.com".
url$ = the full url (address) of the file, ie "https://www.google.com/intl/en_ALL/images/logo.gif".
filename$ = the name of the file you will save it as, ie "logo.gif"
Sat, 28 Apr 2007, 11:08
Blitz3Dman
Oh, ok.

I'll have to have myself a look at that then, because I've been wondering how I can make a WW with no images required...

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 11:12
Blitz3Dman
Hm... what is the signature for a .bmp?
Sat, 28 Apr 2007, 11:20
flying_cucco
What? A curly x maybe?

|edit| Sorry, what I meant was, I don't understand the question. |edit|
Sat, 28 Apr 2007, 11:37
Blitz3Dman
Every type of file has something at the beginning to say that it is this file and it usually takes up several bytes. What I meant was, I don't know what is at the beginning of a .bmp to say that it is when a program reads it.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 11:41
flying_cucco
Oh, right.
As ever, Wikipedia has technical details. The first two bytes are "BM".
Sat, 28 Apr 2007, 11:44
Blitz3Dman
Many thanks, flying_cucco, that's just what I needed

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 12:05
Blitz3Dman
Is anybody getting connected to the server?

I don't know if my code is wrong or if my internet feels like being stubborn.



-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 14:14
bram32
I seem to be able to download it. For some reason, you need to remove the http part from the server when creating the stream.
Then you should check if the stream <> 0, instead of checking if it is one, because when it is valid, "tcp" contains a handle to the stream:

Sat, 28 Apr 2007, 14:22
Blitz3Dman
Thanks.

Now I just need to find out how to read a .png... fun

for some reason imageshack likes to host your bmp as a png OH! I'll make it so many image types are supported and maybe people will never have to use the LoadImage() and LoadAnimImage() commands ever again!!!

(given they can access the internet)


And the new code is this. there still is no server paremeter because it's possible to derive it from the url, thus the newer code:



I suppose the only thing left to do is to have it support some image formats.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 14:25
Paul
I've played around with the code but i can't get it to work, anything special to think about?


|edit|
just saw you're new post, I like the thought of a png loader
Still didn't work though
|edit|

Sat, 28 Apr 2007, 14:28
Blitz3Dman
If you're getting the runtimeerror it's because my avabar was uploaded and saved on the web as a png, not a bmp, but I'm gonna finish the bmp eventually hopefully.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 14:34
Paul
No, i wrote bytes and saved it as an image and let blitz load it.:S

btw, here's a little code to check if a file is a png.

Sat, 28 Apr 2007, 14:35
Blitz3Dman
Meh, meh, meh, meh

ok, another question.

the .png file signature includes the ASCII valuses for PNG and that's all fine and dandy, but then again, they're in hex. And the values are stored in one byte each and I have no idea how to read hex values from a file. Do I still use readbyte()?

|edit| just saw your code, thanks. you posted it while I was posting this. |edit|

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 14:43
Blitz3Dman
O_o

I had no idea of what I was getting into agreeing to write a .png loader, did I?

Wow, I already have a headache

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 14:43
Paul
dec,hex
137=$89
80=$50
78=$4E
71=$47
13=$D
10=$A
26=$1A
10=$A

Think i get them right, What i'm trying to say is that for the computer all the numbers are binary and it doesn't matter if you're using base 10 or 16 or whatever.

Hope you see what i mean(and that I understood your problem correctly).
Sat, 28 Apr 2007, 14:49
Blitz3Dman
Ah, yes, both are true. Thank you.

I think I'm going to do png last, it's giving me a headache and Wikipedia doesn't tell me how one might read the data.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Sat, 28 Apr 2007, 14:52
flying_cucco
Can blitz read PNG files? It would save a lot of headache if you could cache the files to disk and then load them as normal.
Page : 1 2 Next
Prev