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
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Thu Jan 04, 2018 11:23 pm
Hi All,
I search a way to copy a part of a paint image
I tried the script below but it doesn't work
Code: Select all
on copyPartImage
lock screen
hide grc "cadreCopy"
set the tool to "select tool"
click at the topleft of grc "cadreCopy"
drag from the topleft of grc "cadreCopy" to the bottomright of grc "cadreCopy"
wait 2 milliseconds
copy
wait 2 milliseconds
click at 2,2
answer (the clipboarddata["image"] = empty) -- return true
paste
end copyPartImage
Export a snapshot which keeps transparent areas should be an other way but I don't know how.
Best regards
Jean-Marc
Last edited by
jmburnod on Sun Jan 07, 2018 12:32 pm, edited 1 time in total.
https://alternatic.ch
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Fri Jan 05, 2018 1:12 am
Jean Marc.
I placed a few controls on a card. One of them was a button with this in its script:
Code: Select all
on mouseUp
choose pointer tool
click at "10,10"
drag from "10,10" to "500,500"
copy
paste
end mouseUp
When I click the button, I get a copy of each control. The tool remains the pointer tool, and I can go and grab one or more of the duplicates.
Craig Newman
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Fri Jan 05, 2018 10:57 am
Hi Craig,
Your script works fine with pointer tool and controls but i want to do the same with
the select tool and a paint image to copy a part of the image
Jean-Marc
https://alternatic.ch
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Fri Jan 05, 2018 4:27 pm
Jean Marc.
If I change "pointer tool" to "Select tool", place an image, and drag over only part of that image, the whole image is duplicated.
8.1.8
Craig
EDIT.
If i do that several times, only one copy is produced, even though all the previous images underly each other perfectly. Apparently only the topmost image "sees" the select tool.
-
jacque
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
-
Contact:
Post
by jacque » Fri Jan 05, 2018 8:16 pm
I think you'd have better luck using the import snapshot command with the parameter "with effects". You can either set a rect or let the user drag out a region. The new image will appear at the center of the card.
If you want the image in the clipboard you can copy the new image and optionally delete it.
Code: Select all
import snapshot from rect tRect with effects
Or:
import snapshot with effects
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Sat Jan 06, 2018 10:49 am
I tried,
Code: Select all
import snapshot from rect (the rect of grc "cadreCopy") of this cd with effects
Transparent areas are opaque
Error description: Handler: can't find handler
Hint: with
Best regards
Jean-Marc
https://alternatic.ch
-
jacque
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
-
Contact:
Post
by jacque » Sat Jan 06, 2018 10:06 pm
Okay, it's time to pull out the big guns:
Code: Select all
on mouseUp
clone img 1 -- the original image
put the ID of it into tImgID
put the rect of img ID tImgID into tRect
subtract 200 from item 4 of tRect -- adjust this to what you want
crop img ID tImgID to tRect
end mouseUp
When you know it works, you can lock the screen.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Sun Jan 07, 2018 12:52 am
Thanks Jacqueline,
Big gun works.
I have to add 30 to each item of the rect but i don't know why (topleft of my original image = 1,156)
Edit: I was wrong for topleft which is = 156,1
https://alternatic.ch
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Sun Jan 07, 2018 12:06 pm
This works perfectly to export a part (rectangle) of a paint image
Code: Select all
on mouseUp
clone img 1 -- the original image
put the ID of it into tImgID
put the rect of grc "cadrecopy" into tRect
repeat with i = 1 to 4
add 30 to item i of tRect
end repeat
crop img ID tImgID to tRect
put specialfolderpath("documents") & "/" & "TestImg.png" into tPath
export img id tImgID to file tPath as PNG
end mouseUp
Thanks again
Jean-Marc
https://alternatic.ch
-
jacque
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
-
Contact:
Post
by jacque » Sun Jan 07, 2018 6:05 pm
My handler adjusts the rect of the clone directly. Your handler uses the rect of another object, which is why you need to add the offset. If you align the clone to the graphic before cropping, it should work without any math adjustments.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Mon Jan 08, 2018 10:42 am
If you align the clone to the graphic before cropping
That is the trick
https://alternatic.ch