Pergunta

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)

Foi útil?

Solução

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.

Outras dicas

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.)

This worked for me in Pharo 7.0:

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

Afterwards it can be transformed with asMorph.

From the Pharo Mooc:

(ZnEasy getPng: 'http://pharo.org/web/files/pharo.png')
asMorph openInWindow
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top