Cannot resize image to fit graphic

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Cannot resize image to fit graphic

Post by mrcoollion » Wed Nov 30, 2016 3:47 pm

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"

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10125
Joined: Fri Feb 19, 2010 10:17 am

Re: Cannot resize image to fit graphic

Post by richmond62 » Wed Nov 30, 2016 4:16 pm

This won't work as the backGroundPattern of a graphic is set from the id of an img,
not its resized appearance.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10125
Joined: Fri Feb 19, 2010 10:17 am

Re: Cannot resize image to fit graphic

Post by richmond62 » Wed Nov 30, 2016 4:21 pm

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.
squeezer.png
squeezer.livecode.zip
Here's the stack
(13.95 KiB) Downloaded 245 times

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Cannot resize image to fit graphic

Post by jmburnod » Wed Nov 30, 2016 4:35 pm

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
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10125
Joined: Fri Feb 19, 2010 10:17 am

Re: Cannot resize image to fit graphic

Post by richmond62 » Wed Nov 30, 2016 4:40 pm

Have a go with this:
squeezer2.png
squeezer 2.livecode.zip
Here's the stack.
(47.22 KiB) Downloaded 239 times
This "cheats" by taking a snapshot of the resized image and then using
that as the image for the graphic.

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Cannot resize image to fit graphic

Post by mrcoollion » Wed Nov 30, 2016 6:05 pm

@ Jean-Marc: It is an imported image of type imagename.jpg imported on a card named MugShots

@ richmond62: squeezer 2 is indeed cheating LOL :D 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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10125
Joined: Fri Feb 19, 2010 10:17 am

Re: Cannot resize image to fit graphic

Post by richmond62 » Wed Nov 30, 2016 6:18 pm

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.

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Cannot resize image to fit graphic

Post by mrcoollion » Wed Nov 30, 2016 6:49 pm

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 :lol:

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

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Cannot resize image to fit graphic

Post by Klaus » Wed Nov 30, 2016 6:54 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10125
Joined: Fri Feb 19, 2010 10:17 am

Re: Cannot resize image to fit graphic

Post by richmond62 » Wed Nov 30, 2016 6:56 pm

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 ??

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Cannot resize image to fit graphic

Post by Klaus » Wed Nov 30, 2016 7:07 pm

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! 8)

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Cannot resize image to fit graphic

Post by mrcoollion » Fri Dec 02, 2016 4:26 pm

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

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Cannot resize image to fit graphic

Post by mrcoollion » Fri Dec 02, 2016 10:14 pm

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?

Post Reply