[Cuis-dev] scaling an ImageMorph

Weslleymberg Lisboa weslleym.lisboa at gmail.com
Sat Mar 22 00:28:00 PDT 2025


Hi, Mark

It intrigued me that only the image gets scaled but the morph keeps its 
extent when doing `morph scaleBy: 0.75`. I found two things:

1) When we add a morph to a SystemWindow it will be placed inside a 
LayouMorph and receive a LayoutSpec whose default behavior is to make 
the morph fill the layout;

2) There is a method (#minimunExtent) that will calculate the minimum 
extent a morph can have. And guess what? Imagemorph>>#minimumExtent will 
use the original image extent to answer. As a result we see the image 
contained in the morph transformed but the morph itself not, resulting 
in the orange area you see.

I have changed Imagemorph>>#minimumExtent to respect the scaling and it 
works. Except for some 1 pixel wide difference between the image and the 
morph making a very thin orange line appear. But it must be due to 
floating point arithmetic.

```
minimumExtent

	^ image extent + (2 * self interiorOrigin) * self scale
```

Note that the scaling will only affect the morph if you change 
LayoutSpec behavior and make it respect morph's width and height.

```
morph layoutSpec useMorphWidth; useMorphHeight.
```
Took me hours but I think I figured it out :)

Em 21/03/2025 22:27, Mark Volkmann via Cuis-dev escreveu:
> I want to render an image at some percentage less than 100% of its 
> default size.
> I'm not trying to get an image to fill the extent of another morph.
> This code, evaluated in a Workspace, renders an image at its full size.
> What should I change to render it at 50% of that size?
> 
> filePath := '/Users/volkmannm/Pictures/images/altitude1600.jpg'.
> form := Form fromFileNamed: filePath.
> morph := ImageMorph newWith: form.
> SystemWindow new addMorph: morph; openInWorld.
> 
> On Fri, Mar 21, 2025 at 3:02 PM Ezequiel Birman via Cuis-dev <cuis- 
> dev at lists.cuis.st <mailto:cuis-dev at lists.cuis.st>> wrote:
> 
>     errata: “self“ should be “anImageMorph”. I.e.:
> 
>         anImageMorph image: (anImage magnifyTo: anImageMorph morphExtent)
> 
> 
>     On Fri, 21 Mar 2025 at 19:48, Ezequiel Birman <ebirman77 at gmail.com
>     <mailto:ebirman77 at gmail.com>> wrote:
> 
>         I'm not sure what are you trying to do but I'll guess that if
>         you're trying to get the image fill the morphExtent, you cand
>         send `image:` to the imageMorph.
>         anImageMorph image: (anImage magnifyTo: self morphExtent)
> 
>         HTH,
> 
>         -- 
>         Eze
> 
>         On Thu, 20 Mar 2025 at 09:00, Hilaire Fernandes via Cuis-dev
>         <cuis-dev at lists.cuis.st <mailto:cuis-dev at lists.cuis.st>> wrote:
> 
>             __
> 
>             A remark, you should only magnify the form. Not sure it
>             solves your problem, though
> 
>             Le 19/03/2025 à 22:11, Mark Volkmann via Cuis-dev a écrit :
>>             percent := 0.75.
>>             form := Form fromFileNamed: filePath :: magnifyBy: percent.
>>             morph := ImageMorph newWith: form :: scaleBy: percent.
> 
>             -- 
>             http://mamot.fr/@drgeo <http://mamot.fr/@drgeo>
> 
>             -- 
>             Cuis-dev mailing list
>             Cuis-dev at lists.cuis.st <mailto:Cuis-dev at lists.cuis.st>
>             https://lists.cuis.st/mailman/listinfo/cuis-dev <https://
>             lists.cuis.st/mailman/listinfo/cuis-dev>
> 
>     -- 
>     Cuis-dev mailing list
>     Cuis-dev at lists.cuis.st <mailto:Cuis-dev at lists.cuis.st>
>     https://lists.cuis.st/mailman/listinfo/cuis-dev <https://
>     lists.cuis.st/mailman/listinfo/cuis-dev>
> 
> 
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.
> 

-- 
Wéslleymberg Lisboa
Graduado em Sistemas de Informação
Docente no IFFluminense - Campus Itaboraí



More information about the Cuis-dev mailing list