How do I put an image in memory into an image object?
Sarah Reichelt
sarah.reichelt at gmail.com
Sun May 2 22:51:05 EDT 2010
Here is a handler I use for scaling images:
command scaleImage pImgName, pMaxW, pMaxH, pMinW, pMinH, pExpand
put the formattedWidth of pImgName into tFormW
put the formattedHeight of pImgName into tFormH
put 1 into tScale
if pExpand = true then
-- expand to fill max limits, maintaining aspect ratio
put tFormW / tFormH into tAspectRatio
if pMaxW > tFormW then
put pMaxW into tFormW
put pMaxW div tAspectRatio into tFormH
else if pMaxH > tFormH then
put pMaxH into tFormH
put round(pMaxH * tAspectRatio) into tFormW
end if
end if
if tFormW > pMaxW then
put pMaxW / tFormW into tScale
put round(tFormW * tScale) into tFormW
put round(tFormH * tScale) into tFormH
end if
if tFormH > pMaxH then
put pMaxH / tFormH into tScale
put round(tFormH * tScale) into tFormH
put round(tFormW * tScale) into tFormW
end if
if tScale = 1 then
-- only expand if the image has not already been shrunk to fit
if tFormW < pMinW then
put pMinW / tFormW into tScale
put round(tFormW * tScale) into tFormW
put round(tFormH * tScale) into tFormH
end if
if tFormH < pMinH then
put pMinH / tFormH into tScale
put round(tFormH * tScale) into tFormH
put round(tFormW * tScale) into tFormW
end if
end if
put the loc of pImgName into tLoc
set the width of pImgName to tFormW
set the height of pImgName to tFormH
set the loc of pImgName to tLoc
end scaleImage
Use it like this:
scaleImage the long name of img "Pic", 400,400,64,64
or
scaleImage the long name of img "Pic", 400,400,64,64,true
The first one will make the image sized somewhere between 400 and 64
in both dimensions, but maintaining the aspect ratio,
The second one enlarge the image if necessary to make it as big as
possible within the set limits.
HTH,
Sarah
On Mon, May 3, 2010 at 12:44 PM, Bill Vlahos <bvlahos at mac.com> wrote:
> Sarah,
>
> Bingo. That does it.
>
> I can lock the image size but the image doesn't scale evenly. How can I get it to scale evenly within the image boundary?
>
> Bill Vlahos
> _________________
> InfoWallet (http://www.infowallet.com) is about keeping your important life information with you, accessible, and secure.
>
> On May 2, 2010, at 7:01 PM, Sarah Reichelt wrote:
>
>> On Mon, May 3, 2010 at 7:39 AM, Bill Vlahos <bvlahos at mac.com> wrote:
>>> I have an image on disk that is encrypted. I can decrypt the image in memory but how do I put that image variable into an image object? I would also like to automatically fit the image into the predefined object.
>>>
>>> I can set the fileName but that means the file exists on disk not encrypted.
>>
>>
>> What about:
>> put tUnencryptedData into image "Picture"
>>
>> Cheers,
>> Sarah
More information about the use-livecode
mailing list