King Kadelfek
Member
Bitmap Resizer Version: 1.0
By: Krän
Introduction
This script allows to resize bitmaps with anti-aliasing.
It can only reduce pictures, and is super-duper slow.
Krän made this script for me long time ago. I'm looking for some help (or another script which can do the same thing) to improve this script.
Screenshots
<- Original picture
-> resized with RM
---> resized with the script
Script
Instructions
Juste use the methods resize and resize_aa on an existing bitmap to obtain the resized one.
Compatibility
RMXP compatible.
Credits and Thanks
- Krän
- the guy who drawn this nice pikachu
By: Krän
Introduction
This script allows to resize bitmaps with anti-aliasing.
It can only reduce pictures, and is super-duper slow.
Krän made this script for me long time ago. I'm looking for some help (or another script which can do the same thing) to improve this script.
Screenshots

<- Original picture
-> resized with RM
---> resized with the script
Script
Code:
class Bitmap
def resize(zoom)
big_bmp = Bitmap.new(self.width*zoom, self.height*zoom)
big_bmp.stretch_blt(big_bmp.rect, self, self.rect)
return big_bmp
end
def resize_aa(zoom)
bmp = self.zoom_aa_x(zoom)
bmp = bmp.zoom_aa_y(zoom)
return bmp
end
#--------------------------------------------------------------------------------------------------------------------------------
# - Nom : Script de redimensionnement avec Anti-Aliasing
# - Auteur : Krän
# - But : Réduire une image en adoussissant les contours.(Moins de crénelage)
# - Utilisation : Utilisez la fonction zoom_AA_x(zoom) ou zoom_AA_y(zoom)
# sur un bitmap pour que cette fonction renvoie un autre bitmap dont la hauteur ou la largeur
# ont changé. L'argument zoom correspond au rapport entre la nouvelle dimension sur l'acienne.
# - Exemple : bitmap.zoom_AA_x(0.5) renverra la même image que bitmap dont la largeur la
# moitié de bitmap.
#--------------------------------------------------------------------------------------------------------------------------------
#
# Attention : pour le moment ce script ne permet que de réduire des images. L'argument zoom
# doit être inférieur à 1
#
def zoom_aa_x(zoom)
nouvelle_taille = zoom * self.width
nouveau_bitmap = Bitmap.new(nouvelle_taille,self.height)
taille_section = self.width.to_f / nouvelle_taille.to_f
#On analyse le nouveau bitmap dans sa largeur :
for x in 0..nouvelle_taille
#On établit où se trouve le curseur sur l'image d'origine :
curseur = x.to_f * taille_section
#On détermine la section de l'image d'origine correspondant à un pixel de la nouvelle :
debut = curseur.to_int
fin = (curseur + taille_section).to_int
#On détermine les rapports de debut et fin de section (On détermine l'importance des pixels extrèmes) :
rapport1 = (curseur.to_int + 1 - curseur)
rapport2= (curseur + taille_section) - (curseur + taille_section).to_int
for y in 0..self.height
#On crée 4 variables correspondant aux nouvelle couleurs du pixel :
red = 0.0
green = 0.0
blue = 0.0
alpha = 0.0
for i in debut..fin
if i == debut
red += self.get_pixel(i,y).red * rapport1
green += self.get_pixel(i,y).green * rapport1
blue += self.get_pixel(i,y).blue * rapport1
alpha += self.get_pixel(i,y).alpha * rapport1
elsif i == fin
red += self.get_pixel(i,y).red * rapport2
green += self.get_pixel(i,y).green * rapport2
blue += self.get_pixel(i,y).blue * rapport2
alpha += self.get_pixel(i,y).alpha * rapport2
else
red += self.get_pixel(i,y).red
green += self.get_pixel(i,y).green
blue += self.get_pixel(i,y).blue
alpha += self.get_pixel(i,y).alpha
end
end
#On fait les moyennes
red /= taille_section
green /= taille_section
blue /= taille_section
alpha /= taille_section#taille_section
#On donne une couleur au nouveau pixel :
nouveau_bitmap.set_pixel(x, y, Color.new(red,green,blue,alpha))
end
end
return nouveau_bitmap
end
def zoom_aa_y(zoom)
nouvelle_taille = zoom * self.height
nouveau_bitmap = Bitmap.new(self.width,nouvelle_taille)
taille_section = self.height.to_f / nouvelle_taille.to_f
#On analyse le nouveau bitmap dans sa largeur :
for y in 0..nouvelle_taille
#On établit où se trouve le curseur sur l'image d'origine :
curseur = y.to_f * taille_section
#On détermine la section de l'image d'origine correspondant à un pixel de la nouvelle :
debut = curseur.to_int
fin = (curseur + taille_section).to_int
#On détermine les rapports de debut et fin de section (On détermine l'importance des pixels extrèmes) :
rapport1 = (curseur.to_int + 1 - curseur)
rapport2= (curseur + taille_section) - (curseur + taille_section).to_int
for x in 0..self.width
#On crée 4 variables correspondant aux nouvelle couleurs du pixel :
red = 0.0
green = 0.0
blue = 0.0
alpha = 0.0
for i in debut..fin
if i == debut
red += self.get_pixel(x,i).red * rapport1
green += self.get_pixel(x,i).green * rapport1
blue += self.get_pixel(x,i).blue * rapport1
alpha += self.get_pixel(x,i).alpha * rapport1
elsif i == fin
red += self.get_pixel(x,i).red * rapport2
green += self.get_pixel(x,i).green * rapport2
blue += self.get_pixel(x,i).blue * rapport2
alpha += self.get_pixel(x,i).alpha * rapport2
else
red += self.get_pixel(x,i).red
green += self.get_pixel(x,i).green
blue += self.get_pixel(x,i).blue
alpha += self.get_pixel(x,i).alpha
end
end
#On fait les moyennes
red /= taille_section
green /= taille_section
blue /= taille_section
alpha /= taille_section#taille_section
#On donne une couleur au nouveau pixel :
nouveau_bitmap.set_pixel(x, y, Color.new(red,green,blue,alpha))
end
end
return nouveau_bitmap
end
end
Instructions
Juste use the methods resize and resize_aa on an existing bitmap to obtain the resized one.
Compatibility
RMXP compatible.
Credits and Thanks
- Krän
- the guy who drawn this nice pikachu