[squeak-dev] Streaming directly from WebResponse content to
SketchMorph
Bert Freudenberg
bert at freudenbergs.de
Wed Oct 17 23:42:06 UTC 2012
On 17.10.2012, at 16:05, Casimiro de Almeida Barreto <casimiro.barreto at gmail.com> wrote:
> Hello,
>
> Is it possible to stream an image (png) directly from WebResponse to a
> SketchMorph ? I'd like to avoid the burden of saving image in temporary
> file to load it into a SketchMorph.
>
> Tried something like:
>
> ...
>
> response contentStream binary.
> sm := SketchMorph fromStream: resp contentStream.
>
> It fails. Don't know image type.
>
> An alternative would be creating a socket interface so I stream image to
> socket and read from the socket... but it would be verbose... would
> involve forking... would be kind of a dirty job.
>
> [ response streamTo: sock size: response contentLength progress: nil ]
> fork. (...)
>
> sm := SketchMorph fromStream: sock. (...)
>
>
> If some of you can give me a light in this subject... :)
You just need to decode the PNG data into a form, then you can use it in a morph. E.g.:
(PNGReadWriter formFromStream: (HTTPClient httpGet: 'http://squeak.org/img/squeaklogosmallerpng')) asMorph openInHand
- Bert -
More information about the Squeak-dev
mailing list
|