[solved] How to not resize an image in graphic

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

[solved] How to not resize an image in graphic

Post by Zax » Mon May 22, 2017 1:53 pm

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.
Last edited by Zax on Wed May 24, 2017 9:40 am, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Mon May 22, 2017 2:31 pm

Repeat is the default behavior. What is your code doing?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Mon May 22, 2017 3:07 pm

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

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

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

Post by richmond62 » Mon May 22, 2017 5:29 pm

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

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Tue May 23, 2017 9:36 am

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.

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Tue May 23, 2017 10:01 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post by jacque » Tue May 23, 2017 3:58 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 519
Joined: Mon May 28, 2007 10:12 am
Contact:

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

Post by Zax » Tue May 23, 2017 4:39 pm

In my case, I'm glad the image will be lost but you are right to point this, Jacqueline.

Post Reply