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 us开发者_运维技巧e the word picture to avoid confusion with the smalltalk image)
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.
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.)
From the Pharo Mooc:
(ZnEasy getPng: 'http://pharo.org/web/files/pharo.png')
asMorph openInWindow
This worked for me in Pharo 7.0:
ImageReadWriter formFromStream: './assets/player.png' asFileReference binaryReadStream
Afterwards it can be transformed with asMorph
.
精彩评论