Bonjour,
Je voudrais programmer la réduction d'échelle d'un bitmap an respectant les proportions. Je ne peux pas connaître les dimensions du bitmap d'origine car elles varient au cours de l'animation.
Merci
Nos formations à venir :
Bitmap : réduction d'échelle
Débuté par de vita, mars 14 2011 01:44
#1
Posté 14 mars 2011 - 01:44
#2
Posté 14 mars 2011 - 02:32
Bonjour,
voici un script que tu place dans un movie script (script animation et non un script de sprite) et que tu appelle ensuite de la manière suivante :
rescale(member("mon-image") , largeur maxi, hauteur maxi)
Cet exemple redimensionne ton member "mon-image" de sorte qu'il ai les dimensions proportionnelles dans un rectangle de 200x300 maxi :
rescale(member("mon-image") , 200, 300)
--rescale (member , max width, max height)
--Rescales a bitmap cast member to a given max width or max height
--while preserving the original aspect ratio of the image.
--This means that normally one of the dimensions of the new
--bitmap will match one of the max dimensions while the other
--dimension will be equal to or smaller than the other max dimension.
--The new image replaces the original.
--membRef - member reference of original bitmap to rescale.
--maxW - maximum width of the rescaled image.
--maxH - maximum height of the rescaled image.
on rescale membRef,maxW,maxH
wide=membRef.width
high=membRef.height
repeat while wide>maxW or high>maxH
if wide>maxW then
scaler=maxW/float(wide)
wide=wide*scaler
high=high*scaler
nI=image(wide,high,32)
nI.copyPixels(membRef.image,nI.rect,membRef.rect)
membRef.erase()
k=new(#bitmap,membRef)
k.image=nI
end if
wide=membRef.width
high=membRef.height
if high>maxH then
scaler=maxH/float(high)
wide=wide*scaler
high=high*scaler
nI=image(wide,high,32)
nI.copyPixels(membRef.image,nI.rect,membRef.rect)
membRef.erase()
k=new(#bitmap,membRef)
k.image=nI
end if
wide=membRef.width
high=membRef.height
end repeat
end
voici un script que tu place dans un movie script (script animation et non un script de sprite) et que tu appelle ensuite de la manière suivante :
rescale(member("mon-image") , largeur maxi, hauteur maxi)
Cet exemple redimensionne ton member "mon-image" de sorte qu'il ai les dimensions proportionnelles dans un rectangle de 200x300 maxi :
rescale(member("mon-image") , 200, 300)
--rescale (member , max width, max height)
--Rescales a bitmap cast member to a given max width or max height
--while preserving the original aspect ratio of the image.
--This means that normally one of the dimensions of the new
--bitmap will match one of the max dimensions while the other
--dimension will be equal to or smaller than the other max dimension.
--The new image replaces the original.
--membRef - member reference of original bitmap to rescale.
--maxW - maximum width of the rescaled image.
--maxH - maximum height of the rescaled image.
on rescale membRef,maxW,maxH
wide=membRef.width
high=membRef.height
repeat while wide>maxW or high>maxH
if wide>maxW then
scaler=maxW/float(wide)
wide=wide*scaler
high=high*scaler
nI=image(wide,high,32)
nI.copyPixels(membRef.image,nI.rect,membRef.rect)
membRef.erase()
k=new(#bitmap,membRef)
k.image=nI
end if
wide=membRef.width
high=membRef.height
if high>maxH then
scaler=maxH/float(high)
wide=wide*scaler
high=high*scaler
nI=image(wide,high,32)
nI.copyPixels(membRef.image,nI.rect,membRef.rect)
membRef.erase()
k=new(#bitmap,membRef)
k.image=nI
end if
wide=membRef.width
high=membRef.height
end repeat
end
#3
Posté 15 mars 2011 - 11:20
Ca marche ! Merci pour le script.
1 utilisateur(s) li(sen)t ce sujet
0 membre(s), 1 invité(s), 0 utilisateur(s) anonyme(s)









