Page 1 of 1

[solved] How to not resize an image in graphic

Posted: Mon May 22, 2017 1:53 pm
by Zax
Hello,

I would like to use an image file on a graphic object to use the image as background (like the "background-image" CSS property).
When I drop an image file on my graphic object, image is automatically resized in order to fit the graphic, and I don't want this. I found how to extand the graphic rect to display the image at full size but that's not what I want.
I would like the image not to be zoomed out nor to be resized. If image is smaller than graphic rect, it would be nice if the image was repeated (one more, like the "background-repeat" CSS property).

Is it possible to do that?

Thanks for your help.

Re: [HELP] How to not resize an image in graphic

Posted: Mon May 22, 2017 2:31 pm
by FourthWorld
Repeat is the default behavior. What is your code doing?

Re: [HELP] How to not resize an image in graphic

Posted: Mon May 22, 2017 3:07 pm
by Zax
Well, in fact, I can't see what is happening with dropped image file smaller than image zone (object) because content (dropped image) is always automatically fitted to its container (the Livecode object), whatever its size, larger or smaller :(

Re: [HELP] How to not resize an image in graphic

Posted: Mon May 22, 2017 5:29 pm
by richmond62
IF.png
Personally I'd always go with

set the backGroundPattern to grc "XXX" with the id of image "daftPicture"

to guarantee both tiling and no resizing.

The stack is here: https://www.dropbox.com/s/7eeq664wqbrei ... e.zip?dl=0

Re: [HELP] How to not resize an image in graphic

Posted: Tue May 23, 2017 9:36 am
by Zax
Thank you Richmond.

As I was unable to understand how to use your example with a dropped external image file, so I made image object. This is its script:

Code: Select all

on dragEnter
   set the dragAction to "copy"
end dragEnter

on dragDrop
   put the dragData["files"] into myImageFile
      put url ("binfile:" & myImageFile) into me
      set the backGroundPattern of graphic "rr" to (the id of me) -- "rr" is the graphic object I pasted from your sample stack
end dragDrop
Unfortunately, result is the same: dropped image is fitted to the rect of graphic "rr" :(
Maybe I missed something.

Re: [HELP] How to not resize an image in graphic

Posted: Tue May 23, 2017 10:01 am
by Zax
OK, based on Richmond sample, the following script works, though maybe it could be simplified:

Code: Select all

on dragEnter
   set the dragAction to "copy"
end dragEnter

on dragDrop
   lock screen
   import paint from file the dragData["files"]
   if the result = "" then
      set the backGroundPattern of graphic "rr" to (the id of last image)
   delete last image
   else beep
end dragDrop
EDIT: simplified version: only one graphic object, with "dragEnter and "dragDrop" handlers

Code: Select all

on dragEnter
   set the dragAction to "copy"
end dragEnter

on dragDrop
   lock screen
   import paint from file the dragData["files"]
   if the result = "" then
      set the backGroundPattern of me to (the id of last image)
      delete last image
   else beep
end dragDrop

Re: [HELP] How to not resize an image in graphic

Posted: Tue May 23, 2017 3:58 pm
by jacque
If you delete the source image, the graphic won't have a background pattern the next time it is drawn, for example when returning to the card later or on the next startup. I don't know if that matters for your app but just a heads up.

Re: [solved] How to not resize an image in graphic

Posted: Tue May 23, 2017 4:39 pm
by Zax
In my case, I'm glad the image will be lost but you are right to point this, Jacqueline.