soulbw (Normal User)
Newbie
Messaggi: 12
Iscritto: 29/04/2011
|
Questo topic č stato chiuso dal moderatore Ciao a tutti ho bisogno di una funz che fondi insieme piu immagini!!!!!
Diciamo che splitto il file jpg con questa funzione:
public static BufferedImage[] splitImage(BufferedImage img, int cols, int rows)
{
int w = img.getWidth()/cols;
int h = img.getHeight()/rows;
int num = 0;
BufferedImage imgs[] = new BufferedImage[cols*rows];
for(int y = 0; y < rows; y++)
{
for(int x = 0; x < cols; x++)
{
imgs[num] = new BufferedImage(w, h, img.getType());
// Tell the graphics to draw only one block of the image
Graphics2D g = imgs[num].createGraphics();
g.drawImage(img, 0, 0, w, h, w*x, h*y, w*x+w, h*y+h, null);
g.dispose();
num++;
}
}
return imgs;
}
Questa č la funzione che esegue il merge(suppongo di dividere l'immagine in nove pezzettini ...quindi gli passo width=3 height = 3):
public static BufferedImage mergeImage(BufferedImage[] imgFrame, int width, int height)
{
int size = imgFrame.length;
//suppongo frame colonne == righe
int rows =(int) Math.sqrt(size);
int cols = rows;
BufferedImage Im = new BufferedImage(width, height, imgFrame[0].getType());
int i=0;
for( int Irows=0; Irows< rows; Irows++)
{
for(int Icols=0; Icols< cols; Icols++)
{
// chiedo a Graphics di disegnare su Im width x height
Graphics2D g = Im.createGraphics();
g.drawImage(Im, 0, 0, imgFrame.getWidth(), imgFrame.getHeight(), imgFrame.getWidth()*Irows, imgFrame.getHeight()*Icols, imgFrame.getWidth()*Irows+imgFrame.getWidth(), imgFrame.getHeight()*Icols+imgFrame.getHeight(), null);
g.dispose();
i++;
}
}
return Im;
}
Sia Split che Merge funzionano solo che c'č un piccolo problema se a Merge passo il BufferedImage[] ritornato da split mi crea l'immagine tranquillamente...
se invece prendo i BufferedImage ritornati da split li salvo su disco in jpg e poi
da i jpg ricreo BufferedImmage[] mediante un altro metodo la funz merge mi crea un file jpg nero
Qualcuno sa dirmi dove sbaglio!?:P
thx
|