Re: Imported image is distorted
Posted: Thu Dec 10, 2015 11:10 pm
Hi Bernd,
I appreciate your time and help. Have a good weekend.
Regards,
Tom
I appreciate your time and help. Have a good weekend.
Regards,
Tom
Questions and answers about the LiveCode platform.
https://forums.livecode.com/
Code: Select all
case "Library"
mobilePickPhoto "library"
if the result is "Cancel" then exit mouseUp
put the formattedwidth of last image of this card into tWidthSource
put the formattedheight of last image of this card into tHeightSource
-- answer "tWidthSource =" && tWidthSource & cr & "tHeightSource =" && tHeightSource
put the width of me into tWidthDest
put the height of me into tHeightDest
put 0 into tMarge
put imageCrop (tWidthSource, tHeightSource, tWidthDest, tHeightDest, tMarge) into theDimns
-- answer theDimns
-- set the width of last image of this card to item 1 theDimns
-- set the height of last image of this card to item 2 theDimns
-- answer "W" && the width of last image of this card & cr & "H" && the height of last image of this card
lock screen
set the lockLoc of me to false
set the text of me to the text of the last image of this card
set the width of last image of this card to item 1 theDimns
set the height of last image of this card to item 2 theDimns
set the width of me to 240
set the height of me to 240
set the lockLoc of me to true
unlock screenCode: Select all
on resizeTo pDim -- param is either "height" or "width"
if pDim = "height" then
put the 240/formattedHeight of img 1 into tRatio
else -- default is to resize by width
put the 240/formattedwidth of img 1 into tRatio
end if
put img 1 into img 2
set the height of img 2 to (the formattedHeight of img 2 * tRatio)
set the width of img 2 to (the formattedwidth of img 2 * tRatio)
end resizeToCode: Select all
on resizeTo pDim -- pass literal "height" or "width"
if pDim = "height" then
put the 240/formattedHeight of img 1 into tRatio
else -- width is default
put the 240/formattedwidth of img 1 into tRatio
end if
put img 1 into img 2
set the height of img 2 to (the formattedHeight of img 2 * tRatio)
set the width of img 2 to (the formattedwidth of img 2 * tRatio)
put the left of img 2 into tLeft
put the top of img 2 into tTop
crop img 2 to tLeft,tTop,tLeft+240,tTop+240 -- fails here
end resizeTo
Code: Select all
on resizeTo pDim -- pass literal "height" or "width"
if pDim = "height" then
put the 240/formattedHeight of img 1 into tRatio
else -- width is default
put the 240/formattedwidth of img 1 into tRatio
end if
put img 1 into img 2
set the height of img 2 to (the formattedHeight of img 2 * tRatio)
set the width of img 2 to (the formattedwidth of img 2 * tRatio)
set the imagedata of img 2 to the imagedata of img 2
put the left of img 2 into tLeft
put the top of img 2 into tTop
crop img 2 to tLeft,tTop,tLeft+240,tTop+240
end resizeTo
Code: Select all
on mouseUp
local tDim
if environment() is not "mobile" then exit mouseUp
answer "Where is the photo coming from?" with "Library" or "Album" or "Camera" or "Cancel"
put it into tMethod
switch tMethod
case "Library"
mobilePickPhoto "library"
if the result is "Cancel" then exit mouseUp
put the formattedwidth of last img of this card into tWidthSource
put the formattedheight of last img of this card into tHeightSource
if tWidthSource >= tHeightSource then
put "width" into tDim
else
put "height" into tDim
end if
lock screen
set the lockLoc of me to false
set the text of me to the text of the last img of this card
resizeTo tDim
set the imageData of me to the imageData of me
set the width of me to 240
set the height of me to 240
set the lockLoc of me to true
unlock screen
delete the last img of this card
set the uPhotoChanged of this cd to true
breakCode: Select all
on mouseUp
local tDim
if environment() is not "mobile" then exit mouseUp
answer "Where is the photo coming from?" with "Library" or "Cancel"
put it into tMethod
switch tMethod
case "Library" ## Uses resizeTo in the cd script
mobilePickPhoto "library"
if the result is "Cancel" then exit mouseUp
set the uPhotoChanged of this card to false -- just testing if it gets set below
set the name of the last image of this card to "importImage"
put the formattedwidth of img "importImage" into tWidthSource
put the formattedheight of img "importImage" into tHeightSource
if tWidthSource >= tHeightSource then
put "width" into tDim
else
put "height" into tDim
end if
if tDim = "height" then
put 240/(the formattedHeight of img "importImage") into tRatio
else -- width is default
put 240/(the formattedwidth of img "importImage") into tRatio
end if
lock screen
set the lockLoc of me to true
set the text of me to the text of image "importImage"
if tDim = "width" then
set the width of me to 240
set the height of me to the formattedHeight of me * tRatio
else
set the height of me to 240
set the width of me to the formattedWidth of me * tRatio
end if
set the lockLoc of me to true
unlock screen
delete image "importImage"
set the imageData of me to the imageData of me -- fix image to this size
set the uPhotoChanged of this cd to true
break
end switch
end mouseUp