
//==========================================================================

//          Resumen de operaciones con imgenes

//==========================================================================


    BufferedImage   buffImage = null;
    Graphics2D  g2 = null;
    Image   imag = null;
    int     mapa[];
    int     nfil, ncol;
    int     v;


//==========================================================================

//      Lectura de un fichero GIF o JPG
 

    imag = Toolkit.getDefaultToolkit ().getImage (dirFichero);
 
    do
    {
        nfil = imag.getHeight (this);
        ncol = imag.getWidth (this);
    }  
    while ((nfil < 0) || (ncol < 0));


//==========================================================================

//  Crea un mapa de datos a partir de un objeto Image 
//  En el mapa se queda con los tres ltimos bytes, o sea las componentes RGB,
//  o el ltimo si es en gris

    mapa = new int[nfil * ncol];
                            
    try 
    {
        PixelGrabber pixGrab = new PixelGrabber (imag, 0, 0,
                     ncol, nfil, mapa, 0, ncol); 

        if (pixGrab.grabPixels () &&
            ((pixGrab.getStatus () & ImageObserver.ALLBITS) != 0))
        {
            for (i = 0; i < nfil * ncol; i ++)
            {
                if (bytesPixel == 1)
                    mapa[i] = mapa[i] & 0xff;
                else
                    mapa[i] = mapa[i] & 0xffffff;
            }
        }
        else
            System.out.println ("ERROR");
    }

    catch (InterruptedException e) 
    {
        System.out.println ("Otro error");
    }


//==========================================================================

//  Para crear una imagen a partir de un vector mapa de datos
    

//  Cada dato del mapa tiene 4 bytes. Los tres ltimos son las componentes 
//  RGB del color y el primero es todo unos, o sea FF.

    imag = Toolkit.getDefaultToolkit ().createImage 
                (new MemoryImageSource (col, fil, map, 0, col));


                                                                                                                                                                
//==========================================================================
                                                                                                                                                                
//  A partir de un objeto Image crea un buffer y copia en l la imagen


    buffImage = new BufferedImage (ncol, nfil,
                        BufferedImage.TYPE_INT_ARGB);
    g2 = buffImage.createGraphics ();
 
        //  Dibuja la imagen en el "buffer"
 
    do
        g2.drawImage (imag, 0, 0, this);
    while
        (buffImage.getRGB (ncol-1, nfil-1) == 0);        
                                                                                                                                                                
//==========================================================================
                                                                                                                                                                
//      Para enviar un dato al "buffer"
                                                                                                                                                                
    buffImage.setRGB (j, i, v);        
                                                                                                                                                                
                                                                                                                                                                
//==========================================================================
                                                                                                                                                                
//      Para leer un dato del "buffer"

    v = buffImage.getRGB (j, i);        

//==========================================================================

//      Dibuja la imagen cada vez que es necesario  
//      (Basta una de las dos formas)
  
    public void paint (Graphics g)
    {
        if (buffImage != null)
            g.drawImage (buffImage, 5, 25, this);

        if (imag != null)
            g.drawImage (imag, 5, 25, this);
    }
