Oppure

Loading
Questo topic e' stato chiuso dal moderatore.
04/05/11 20:25
soulbw
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[i].getWidth(), imgFrame[i].getHeight(), imgFrame[i].getWidth()*Irows, imgFrame[i].getHeight()*Icols, imgFrame[i].getWidth()*Irows+imgFrame[i].getWidth(), imgFrame[i].getHeight()*Icols+imgFrame[i].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
aaa
05/05/11 12:47
netarrow
Questo topic è in violazione di una o più norme del regolamento: pierotofy.it/pages/extras/forum/9/3839-regolamento/ .
    
Dopo averlo letto riapri un nuovo topic assicurandoti di aver rispettato le regole. Grazie per la tua pazienza.
aaa