I've got to do some lingo-ese and I don't think what I'm doing is very
elegant; I want to take an output rect and an incoming image and return an
image with a user's choice of:
Actual size Scale to fit Fit height Fit width Pin smaller Pin larger
At the risk of causing more damage to volkswagons, try something like this
on getImage (inputImg, returnRect, sizeOption)
returnImg = image(returnRect.width, returnRect.height, inputImg.depth) returnImg.fill(returnImg.rect, rgb(0,0,0))
case (sizeOption) of
#ActualSize:
-- assuming you want to centre the input on the output image
fromRect = getCentreRect(returnRect, inputImg.rect)
destRect = getCentreRect(fromRect, returnRect)
returnImg.copyPixels(inputImg, destRect, fromRect) #ScaleConstrained:
if inputImg.width > inputImg.height then
theScale = float(returnImg.width)/inputImg.width
else
theScale = float(returnImg.height)/inputImg.height
end if
destRect = getCentreRect(inputImg.rect * theScale, returnRect)
returnImg.copyPixels(inputImg, destRect, inputImg.rect) #ScaleNotConstrained:
returnImg.copyPixels(inputImg, returnImg.rect, inputImg.rect) #FitHeight:
theScale = float(returnImg.height)/inputImg.height
destRect = getCentreRect(inputImg.rect * theScale, returnRect)
returnImg.copyPixels(inputImg, destRect, inputImg.rect) #FitWidth:
theScale = float(returnImg.width)/inputImg.width
destRect = getCentreRect(inputImg.rect * theScale, returnRect)
returnImg.copyPixels(inputImg, destRect, inputImg.rect)--etc end case
return returnImg end
on getCentreRect (centreThis, onThis)
-- returns a rect which is the first rect centred on the second
offX = onThis.left + onThis.width/2 - centreThis.width/2
offY = onThis.top + onThis.height/2 - centreThis.height/2
return rect(0,0,centreThis.width, centreThis.height).offset(offX, offY)
end
Luke
-- ***************************************************************** Mecca Medialight Pty Ltd
Mecca Medialight: 111 Moor Street Fitzroy, Vic. 3065 Tel +613 9416 2033 Fax +613 9416 2055
Mecca Medialight Sound Studio: 1 Bakehouse Lane http://www.meccamedialight.com.au/
*****************************************************************
This email and any files transmitted with it may contain information which is privileged, confidential and protected from disclosure. If you have received this email in error please notify [EMAIL PROTECTED] and do not use, disclose, copy, distribute or retain any of it without our authority.
*****************************************************************
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]
