Page 1 of 1
copy a part of a paint image by script Solved
Posted: Thu Jan 04, 2018 11:23 pm
by jmburnod
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
Re: copy a part of a paint image by script
Posted: Fri Jan 05, 2018 1:12 am
by dunbarx
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
Re: copy a part of a paint image by script
Posted: Fri Jan 05, 2018 10:57 am
by jmburnod
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
Re: copy a part of a paint image by script
Posted: Fri Jan 05, 2018 4:27 pm
by dunbarx
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.
Re: copy a part of a paint image by script
Posted: Fri Jan 05, 2018 8:16 pm
by jacque
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
Re: copy a part of a paint image by script
Posted: Sat Jan 06, 2018 10:49 am
by jmburnod
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
Re: copy a part of a paint image by script
Posted: Sat Jan 06, 2018 10:06 pm
by jacque
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.
Re: copy a part of a paint image by script
Posted: Sun Jan 07, 2018 12:52 am
by jmburnod
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
Re: copy a part of a paint image by script
Posted: Sun Jan 07, 2018 12:06 pm
by jmburnod
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
Re: copy a part of a paint image by script Solved
Posted: Sun Jan 07, 2018 6:05 pm
by jacque
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.
Re: copy a part of a paint image by script Solved
Posted: Mon Jan 08, 2018 10:42 am
by jmburnod
If you align the clone to the graphic before cropping
That is the trick
