ramiromd
ramiromd

Reputation: 2029

Display an image from URL

I need get an image from a URL and display in a view. How can do this in Cincom Smalltalk? For example, I have this image URL:

http://news.bbcimg.co.uk/media/images/64001000/jpg/_64001280_63976026.jpg

And I wish display the image. I try:

|req content reader|
req := HttpRequest
    get:'http://news.bbcimg.co.uk/media/images/64001000/jpg/_64001280_63976026.jpg' asURI.
content:=req execute.
reader := JPEGImageReader new.
reader from: content byteSource.

But it doesn't work. Cincom Smalltalk says:

Image incomplete or partially corrupted JFIF marker expected.

when I execute: JPEGImageReader>>parseFirstMarker.

Upvotes: 1

Views: 941

Answers (1)

David Buck
David Buck

Reputation: 2847

The "byteSource" method is returning a stream that's already positioned to the end of file. When the JPEG reader starts to read, I hits the end and aborts.

You really shouldn't be using the byteSource method. If the contents of the URI are compressed, you won't get them properly decompressed. You should fetch the byteContents and open a readStream on that result as follows:

|req content reader image |
req := HttpRequest
    get:'http://news.bbcimg.co.uk/media/images/64001000/jpg/_64001280_63976026.jpg' asURI.
content:=req execute.
reader := JPEGImageReader new.
image := (reader from: content byteContents readStream) image

Upvotes: 2

Related Questions