[Gambas-user] Download JPG with HttpClient to memory

Benoît Minisini gambas at ...1...
Fri Feb 18 14:24:29 CET 2011


> Hi list
> 
> I am unable to download a JPG image from an IP Webcam and feed a
> PictureBox, without creating a file-like object.
> 
> I'm using HttpClient to fetch the images asyncronously, but the buffer
> at last is only a string representation of its binary data.
> 
> How do I convert this data into an actual image object for viewing in a
> PictureBox or DrawingArea?
> 
> This is my code so far:
> 
> 
> ' Gambas class file
> 
> PUBLIC $http AS HttpClient
> PRIVATE $pic AS String
> 
> PUBLIC SUB Form_Open()
>   $http = NEW HttpClient AS "MyStream"
>   $http.Async = TRUE
>   $http.Timeout = 3
>   $http.URL = "http://192.168.1.10:4500/axis-cgi/jpg" &
>               "/image.cgi?resolution=320x240"
> END
> 
> PUBLIC SUB Timer1_Timer()
>   $http.Get
> END
> 
> PUBLIC SUB MyStream_Read()
>   DIM buffer AS String
>   READ #LAST, buffer, Lof(LAST)
>   $pic &= buffer
> END
> 
> PUBLIC SUB MyStream_Finished()
>   ' Here I want to feed the picturebox with the buffered JPG
>   ' but $pic only contains a string repr of the binary image
>    PictureBox1.Refresh
> END
> 
> PUBLIC SUB btnStart_Click()
>   Timer1.Start
> END
> 
> PUBLIC SUB btnStop_Click()
>   Timer1.Stop
> END
> 
> PUBLIC SUB btnExit_Click()
>   Timer1.Stop
>   ME.Close
> END
> 
> I'd like to avoid using a file, is it possible to do from RAM?
> 

At the moment, no.

But if you get the HTTP answer, save it to /tmp, reload it as a picture, and 
delete the file, there is a good chance that the file does not hit the disk at 
all. And if you have a /tmp that is mounted on a RAM file system, it is almost 
sure!

Regards,

-- 
Benoît Minisini




More information about the User mailing list