It works with RGBArrays. First, we need a function to resize Arrays:

code:



private int[] reescalaArray(int[] ini, int x, int y, int x2, int y2) {
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++) {
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++) {
int dx = xx * x / x2;
out[(x2*yy)+xx]=ini[(x*dy)+dx];
}
}
return out;
}

INI: Source Array
X: Width of Source Array
Y: Height of Source Array
X2: Width of the Output Array
Y2: Height of the Output Array
Returns OUT (Output Array)
How to use it:

code:



//Need an image
Image temp=null;
try {
temp = Image.createImage("/tr1.gif");
} catch (IOException e) {
System.err.println("Can`t load the image : " + e.toString());
}
//Need an array (for RGB, with the size of original image)
int rgb[] = new int[temp.getWidth()*temp.getHeight()];
//Get the RGB array of image into "rgb"
temp.getRGB(rgb,0,temp.getWidth(),0,0,temp.getWidth(),temp.getHeight());
//Call to our function and obtain RGB2
int rgb2[] = reescalaArray(rgb,temp.getWidth(),temp.getHeight(),newX,newY);
//Create an image with that RGB array
Image temp2 = Image.createRGBImage(rgb2,newX,newY,true);
 
author is LuisMiguel Rubio
Posted July 27, 2005 09:37 AM