amccormack
amccormack

Reputation: 13927

How do I load a picture (image) into smalltalk

How do you load a picture into smalltalk? I have found several examples of how to display an image once it is a class resource, but can't find a way to import the picture into my smalltalk environment. (I use the word picture to avoid confusion with the smalltalk image)

Upvotes: 5

Views: 2037

Answers (4)

Fuhrmanator
Fuhrmanator

Reputation: 12882

From the Pharo Mooc:

(ZnEasy getPng: 'http://pharo.org/web/files/pharo.png')
asMorph openInWindow

Upvotes: 1

danlei
danlei

Reputation: 14291

One possibility for Squeak would be:

HandMorph attach: (SketchMorph fromStream:
  'https://squeak.org/img/features/morphic.png'
    asUrl retrieveContents contentStream).

(This used to work for Pharo, too, but seems to have been removed.)

Upvotes: 1

itmuckel
itmuckel

Reputation: 1420

This worked for me in Pharo 7.0:

ImageReadWriter formFromStream: './assets/player.png' asFileReference binaryReadStream

Afterwards it can be transformed with asMorph.

Upvotes: 0

amccormack
amccormack

Reputation: 13927

To load an image as a class resource, the following code should be executed in the workspace.

ImageReader imageFromFile: 'picture.bmp' 
    toClass: Namespace.MyClass selector: #AccessMethod

where 'picture.bmp' is the image file you want to load, NameSpace.MyClass is the class you want the file to be a resource to, AccessMethod is the name of the method called to return the picture.

Upvotes: 3

Related Questions