user8190738
user8190738

Reputation:

Scaling an ImageMorph in Smalltalk (Pharo)

I am searching for a way to scale an Image Morph in Pharo. This is what I've tried so far, it did not result in an error, but the Image was the original size:

initialize 
| pL pR size pSize |

size := 300.
pSize := size / 12.

super initialize .
self image: (ImageReadWriter formFromFileNamed: 'face.png').
self position: 100@100.
self resize: 100@100.

Upvotes: 1

Views: 455

Answers (1)

Andrei Chis
Andrei Chis

Reputation: 723

One way to resize an image is to use the scaledToSize: method from the Form class.

imageForm := ZnEasy getPng: 'https://pharo.org/web/files/pharo.png'.
imageForm scaledToSize: 100@30.

If you need to have more customized strategies for resizing you can wrap the image form in a AlphaImageMorph. For example, in the example below the image is extended to fit the size of the window:

(AlphaImageMorph withForm:(ZnEasy getPng: 'https://pharo.org/web/files/pharo.png'))
   layout: #scaledAspect;
   openInWindow.

Upvotes: 2

Related Questions