Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - AiutoOoo qualcuno sa come si possono fondere piu jpg in un unico jpg??
Forum - Java - AiutoOoo qualcuno sa come si possono fondere piu jpg in un unico jpg??

Avatar
soulbw (Normal User)
Newbie


Messaggi: 12
Iscritto: 29/04/2011

Segnala al moderatore
Postato alle 22:25
Mercoledė, 04/05/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

PM
Avatar
netarrow (Admin)
Guru^2


Messaggi: 2502
Iscritto: 12/05/2004

Segnala al moderatore
Postato alle 14:47
Giovedė, 05/05/2011
Questo topic č in violazione di una o pių norme del regolamento: http://www.pierotofy.it/pages/extras/forum/9/3839-regolame ... .
    
Dopo averlo letto riapri un nuovo topic assicurandoti di aver rispettato le regole. Grazie per la tua pazienza.

PM