copy or move image from card to card

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
reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

copy or move image from card to card

Post by reelstuff » Wed Aug 15, 2007 1:22 am

I am working on building a stack to allow the user to open a graphic file from their computer, So far I have an image that is shown from an image object iData

Code: Select all

--So I am putting the GetFileData function into iData from mouse up in button script
put GetFileData() into iData

--Multi platfrom Type, name the image file from function in card script

function GetFileData pPrompt, pMacType, pWinType, pTextOrBinary 
  if pPrompt is empty then put "Select a file:" into pPrompt 
  if the platform is "MacOS" then 
    answer file pPrompt of type pMacType 
   else 
    answer file pPrompt with filter pWinType 
  end if
  if it is empty then exit to top 
set the filename of img "iData" to it
end GetFileData 

Now I want to move or copy the image file (iData) to another card in the same stack, called "Template"

I thought of a number of ways to do this but I am a little fuzzy on some of the syntax,

I have an image object on the "template" card,
and called iData2, so I am wondering the best way to move the image from iData on card one, to the image object on card 2, iData2
using a button, script,

Any help is always appreciated, thanks

Tim

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Aug 15, 2007 9:06 am

Tim,

Do you actually want to copy the image, move it, or only display it on another card?

copy:

copy img id 1010 of cd 1 to cd 2

(re)move:
copy img id 1010 of cd 1 to cd 2
delete img id 1010 of cd 1

display: create a button on cd 2 and use the following syntax:

set the icon of img 1 of cd 2 to 1010

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Post by reelstuff » Wed Aug 15, 2007 1:49 pm

Hi, first thank you for your reply, I wanted to give the user the opportunity to examine the image they choose, before copying the image to the next card,

the idea is to gradually create a "template" of user input, and or selections for various options in creating the template for use as an export file later in the application.

so when I copy the image from cd1 (iData) to cd 2 (iData2)

it copies iData into IData2, so I now have an image inside an image object.

Interesting, result, I have run into a number of issues, which I will need to evaluate,

Thank you for your help.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Aug 15, 2007 4:43 pm

Hi Tim,

Maybe you want:

put the topleft of img 1 of cd 2 into myTL
set the rect of img 1 of cd 2 to the rect of img 1 of cd 1
set the text of img 1 of cd 2 to the text of img 1 of cd 1
set the topleft of img 1 of cd 2 to myTL

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Post by reelstuff » Wed Aug 15, 2007 7:38 pm

Hi and thank you, here is what I ended up with,

Code: Select all

on mouseUp
 copy img "iData" of cd 1 to cd 2 
 put the topleft of img 1 of cd 2 into myTL 
 set the rect of img 1 of cd 2 to the rect of img 1 of cd 1 
 set the text of img 1 of cd 2 to the text of img 1 of cd 1 
 set the topleft of img 1 of cd 2 to myTL 
 go to the next card
end mouseUp
Im not sure I got it exactly right, but I created a rectangle and named it myTL when the script executes, the image is copied to the next card and displays great.

I was not sure of how the text of img string works,

Thanks.

Tim

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

Post by Klaus » Wed Aug 15, 2007 7:45 pm

Hi reeelstuff,

what Marks means is that both images have to have EXACT dimensions if you want to transfer the imagedata from one image to the next, or you will get strange results.

But since you are just copying images, the script is not necessary for your needs and you can omit some lines of the script:

Code: Select all

on mouseUp 
 copy img "iData" of cd 1 to cd 2 
 put the topleft of img 1 of cd 2 into myTL 
 set the topleft of img 1 of cd 2 to myTL 
 ## So both images are at the same place on both cards
 go to the next card 
end mouseUp 

Best from germany

Klaus

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Post by reelstuff » Wed Aug 15, 2007 8:33 pm

Oh, I see, thank you.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Aug 15, 2007 8:47 pm

Hi Klaus and Tim,

Additionally, I meant that you don't necessarily have to copy the image object. Tim said, he has an image inside an image, so I presume he is copying new image objects. Tim, you should note that image objects and their contents are two different things, just like the text of a field and the field itself.

So, if you have an image on card 1 and an image on card 2, you can set the contents (text) of the image on card 2 to the text of the image on card 1. That way, you copy the contents, but not the image objecty, which is already on card 2.

I don't know whether this is exactly what you want, but it seems the right way to do it to me.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply