Image Referenced or As Control

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Image Referenced or As Control

Post by hamlynart » Sun Aug 16, 2009 11:49 am

Hi Folks,

I thought I had imported all my images into my project "as control" images but looking at the object inspector it appears that they're all referenced.

Is there a way to convert them to control images? Or do I have to import them all again and place them? :(

It's a shame the Image library doesn't have more info i.e: whether images are reference or control and perhaps a button to convert between the two.

Any ideas or advice would be greatly appreciated.

Jim H

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

Post by Klaus » Sun Aug 16, 2009 12:06 pm

Hi Jim,

you can use a little script that I once wrote for this purpose, it will loop through all cards of your stack
and put the binary data of the referenced images into the images!

Code: Select all

on mouseUp
   set the defaultstack to "Name of your stack with referenced images here!"
  lock screen
  lock messages

  ## Loop through all cards of this stack:
  repeat with i = 1 to the num of cds
    set cursor to busy

    ## Loop through all images on card:
    repeat with k = 1 to the num of images of cd i
      put the filename of image k of cd i into tFileName

      ## No referenced image, so carry on...
      if tFileName = empty then
          next repeat
      end if
     
      ## Put the binary data into the image (that is the same as "import as control"):
      put url("binfile:" & tFileName) into image k of cd i
    end repeat
  end repeat
  unlock screen
  unlock messages
  answer "Done!" & CR & "Don't forget to save stack" && QUOTE & "Name of your stack with referenced images here!" & QUOTE & "!"
end mouseUp
Hope that helps!


Best

Klaus

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Sun Aug 16, 2009 9:11 pm

Hi Klaus,

That's neat - it actually converts reference images to "control images".

However:

It works great if I import the images as a folder. But if I import them individually and run your script they simply disappear without a trace!!!???

Jim H

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Aug 16, 2009 9:36 pm

Jim,

for referenced images that I want to loose the reference and become "resident" imaged I use

Code: Select all

on mouseUp pMouseBtnNo
    set the imagedata of image 1 to the imagedata of image 1
end mouseUp
this eliminates the reference and you can see in the inspector that the filename is empty.
I did not try Klaus's code but you can try this.
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Aug 16, 2009 10:16 pm

Jim,

one thing to consider when using

Code: Select all

on mouseUp pMouseBtnNo 
    set the imagedata of image 1 to the imagedata of image 1 
end mouseUp
is that in case you had resized your original image to a smaller size then this code will fix the smaller size, discarding the information of the larger image.
Just in case...
regards
Bernd

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Sun Aug 16, 2009 11:51 pm

Hi Bernd,

Thanks for that. I'm a bit confused though. What should my image be named for this to work?

I've tried "image 1" and just "1" to no avail. I also tried to make a simple plugin with a button and this script:

Code: Select all

on mouseUp
set the imagedata of the selectedObject to the imagedata of the selectedObject
end mouseUp
scratch that - I just tried it again and it works!!!

Great! Thanks a million.

Jim H

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

Post by Klaus » Mon Aug 17, 2009 8:29 am

hamlynart wrote:Hi Klaus,

That's neat - it actually converts reference images to "control images".

However:

It works great if I import the images as a folder. But if I import them individually and run your script they simply disappear without a trace!!!???

Jim H
???

I have been using this script for years and never had disappearing images?
What do you mean "import the images as a folder"?

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Mon Aug 17, 2009 12:08 pm

Hi Klaus,

I've tried it again and it's doing the same thing.

New Mainstack.
One button with your script in it.
If I import single images (one after the other) as reference and click the button all the images vanish.

If I import as "New Referenced Control" -> "reference "All Images in Folder..." and click your button script the images stay put and get converted to control images.

Jim

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

Post by Klaus » Mon Aug 17, 2009 12:22 pm

Hi Jim,

just did some tests and it looks as if my technique will only work with JPG and PNG image formats!?

A BMP file "disappeared" here, too!
Are you using something different than JPG and/or PNG?


Best

Klaus

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Mon Aug 17, 2009 12:46 pm

I used png images on OSX

but it does it with jpg also.

HTH

Jim H

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

Post by Klaus » Mon Aug 17, 2009 12:51 pm

Hi Jim,

hm, worked here on OS X with JPG and PNG images in my test a couple of minutes ago?
Sorry, no idea in the moment...


Best

Klaus

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Aug 17, 2009 1:14 pm

You should copy the imageData as well as the alphaData of the image, and make sure the target has the same width and height as the source image. To avoid that, use the unfortunately named text property of the image.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Mon Aug 17, 2009 1:24 pm

Hi Jan,
somehow

Code: Select all

set the text of image 1 to the text of image 1
does not seem to work for me. Just setting either the imagedata or the alphadata gets rid of the "filename" and the image is an "imported" image. Apart from setting the size of an image permanently to the displayed size I never had any problem with this.
Klaus's solution should work around this limitation.
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Mon Aug 17, 2009 1:32 pm

@Klaus and @Jim,

could it have to do with absolute or relative file referencing? In the preferences is an option for images to always use absolute references. Under files and memory the last option.
Just a guess, I seem to remember that I had problems with this once, but dont remember it very well.
regards
Bernd

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Mon Aug 17, 2009 3:47 pm

Blimey, yes that's it!
I had "Always use absolute file paths for images" unchecked.
If I have it checked the code works fully.

Thanks

Jim

Post Reply