Display an image from URL
Asked Answered
L

1

1

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.

Livengood answered 19/4, 2014 at 18:42 Comment(0)
R
2

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
Radiocarbon answered 20/4, 2014 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.