Page 1 of 1
Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 3:47 pm
by mrcoollion
I cannot seem to resize an image on a card named MugShots to get it to fit in a graphic object.
No errors, it just does not resize?
Am i doing something wrong?
In the variable MugShot exists the imagename.jpg
The code does place the image as backgroundPattern of graphic "VieuwMugShot" of this card .
Code: Select all
put the width of image MugShot of card "MugShots" into tiWidth
put the height of image MugShot of card "MugShots" into tiHeight
put the width of graphic "VieuwMugShot" of this card into tgWidth
put the height of graphic "VieuwMugShot" of this card into tgHeight
set the Width of image MugShot of card "MugShots" to tgWidth
set the Height of image MugShot of card "MugShots" to tgHeight
set the backgroundPattern of graphic "VieuwMugShot" of this card to the id of image MugShot of card "MugShots"
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 4:16 pm
by richmond62
This won't work as the backGroundPattern of a graphic is set from the id of an img,
not its resized appearance.
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 4:21 pm
by richmond62
Here's a stack with 2 graphics, and despite resizng the image the original size is used as the backGroundPattern
Have a look at the scripts in the buttons.
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 4:35 pm
by jmburnod
I tested your script and it works (no proportionally) with an imported image (without filename)
but not if that is a referenced image (with filename) which show only a part of the image.
Is that the case ?
For a proportionally resize, there is a lesson here
http://lessons.livecode.com/m/4071/l/15 ... e-an-image
Best regards
Jean-Marc
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 4:40 pm
by richmond62
Have a go with this:
This "cheats" by taking a
snapshot of the resized image and then using
that as the image for the graphic.
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 6:05 pm
by mrcoollion
@ Jean-Marc: It is an imported image of type imagename.jpg imported on a card named MugShots
@ richmond62: squeezer 2 is indeed cheating LOL

but it does work
In my case however I am needing this in a datagrid with many lines (think chat lines) with each line showing a mugshot of somebody.
The end result needs the image to come from a database field (sqlite) and I am working towards this.
Copying an image for each line does seem to have a big impact on memory. I would rather refer to an image.
The reason I wanted to try use graphic objects is that I can make them round just by using the oval graphic object and setting the image as background in the same size as the oval graphic object.
You gave me an idea though. I can import the image once and resize it and then refer for each oval graphic object to that new image ID. Therefor only have the image copied only once.
I will get back on this tomorrow.
If any of you got a brilliant idea to solve this let me know.
Thanks,
Paul
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 6:18 pm
by richmond62
I can import the image once and resize it and then refer for each oval graphic object to that new image ID. Therefor only have the image copied only once.
Of course, once you have resized your imported image and taken a snapshot of it, you can delete the original image to save space.
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 6:49 pm
by mrcoollion
Put the idea in practice and it works great.
What do I do.
If the resized image if not already there I Import the image after doing a resize of the original image, then move it to my image holder card and use it as a backgroundPattern of the oval graphic object.
Thanks richmond62 for the cheat stack squeezer 2.livecode .
Better a smart cheat than no solution at all
Here is the code is used.
Code: Select all
put "MugShots" into tImageHolderCard
put "VieuwMugShot" into tGraphicObjectName
put the width of graphic tGraphicObjectName of this card into tgWidth
put the height of graphic tGraphicObjectName of this card into tgHeight
set the resizequality of image MugShot of card tImageHolderCard to "Best"
set the Width of image MugShot of card tImageHolderCard to tgWidth
set the Height of image MugShot of card tImageHolderCard to tgHeight
put "new"&MugShot into NewMugshotName
if there is not an image NewMugshotName of card tImageHolderCard then
set the locked of image MugShot of card tImageHolderCard to true
import snapshot from image MugShot of card tImageHolderCard
set the visible of last image to false
set the name of last image to NewMugshotName
copy img NewMugshotName to cd tImageHolderCard
delete img NewMugshotName of this card
set the visible of img NewMugshotName of cd tImageHolderCard to true
end if
set the backgroundPattern of graphic tGraphicObjectName of this card to the id of img NewMugshotName of card tImageHolderCard
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 6:54 pm
by Klaus
Hi Paul,
1. did you "set the lockloc of img "Mugshot" to TRUE", via script or in the inspector?
2. Use a button and set its ICON property to the ID of your image instead of using a graphic with a backpattern.
This way you will only see the image ONCE in your button, no matter how big you size your button!
And you are only referencing the image, no memory overhead, no matter how many buttons you use to display the image!
Best
Klaus
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 6:56 pm
by richmond62
Use a button and set its ICON property to the ID of your image instead of using a graphic with a backpattern
Always supposing one can have buttons in a datagrid ??
Re: Cannot resize image to fit graphic
Posted: Wed Nov 30, 2016 7:07 pm
by Klaus
richmond62 wrote:Use a button and set its ICON property to the ID of your image instead of using a graphic with a backpattern
Always supposing one can have buttons in a datagrid ??
One can, if the datagrid is of type FORM, which is also mandatory if you want to add a graphic to it!

Re: Cannot resize image to fit graphic
Posted: Fri Dec 02, 2016 4:26 pm
by mrcoollion
Hi Klaus,
Using a graphic is a test. And it all works (still have some bugs though). I have got buttons, graphics and text fields in the datagrid. Also the size of the line is per line different depending on the amount of text.
The reason for using a graphic is that I want to show a round picture of a mugshot while the picture actually is square. An oval graphic seemed to to be the easiest way to achieve this.
Thanks for the support

Re: Cannot resize image to fit graphic
Posted: Fri Dec 02, 2016 10:14 pm
by mrcoollion
Made a separate datagrid related post from this !!
Have a problem.
When I add a line to the datagrid it does not show below the previous line but it comes inplace of the first line?
Maybe I broke something because in earlier version it did work but I cannot find what.
Using
Code: Select all
set the dgData of group "DataGridForm" to theDataA
To update the datagrid.
(If you want i can upload the stack but it is in very rough form.)
Any tips?