Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di percky
    Registrato dal
    May 2001
    Messaggi
    118

    problemi con un ciclo for

    import java.io.*;
    import javax.imageio.*;
    import java.awt.image.*;
    import java.awt.geom.*;

    public class JPGImage
    {
    public JPGImage(String srcFileName,String destFileName,int
    thumbNailSize) throws Exception
    {
    // Read in original image to create thumbnail from
    File inFile = new File(srcFileName);
    BufferedImage bufferedImage = ImageIO.read(inFile);
    bufferedImage.flush();

    // Calculate scale so image fits in a square area of thumbNailSize
    int imageWidth = bufferedImage.getWidth();
    int imageHeight = bufferedImage.getHeight();

    int componentWidth = thumbNailSize;
    int componentHeight = thumbNailSize;
    double scale = -1;

    if ( imageWidth == componentWidth && imageHeight ==
    componentHeight){
    scale = 1;
    }
    else if ( imageWidth <= componentWidth && imageHeight <=
    componentHeight)
    {
    double heightScale = ((double)componentWidth) / ((double)
    imageWidth);
    double widthScale = ((double)componentHeight) / ((double)
    imageHeight);
    if ( heightScale < widthScale ) scale = heightScale;
    else scale = widthScale;
    }
    else if ( imageWidth > componentWidth && imageHeight <=
    componentHeight)
    {
    double heightScale = ((double)componentWidth) / ((double)
    imageWidth);
    scale = heightScale;
    }
    else if ( imageWidth <= componentWidth && imageHeight >
    componentHeight)
    {
    double widthScale = ((double)componentHeight) / ((double)
    imageHeight);
    scale = widthScale;
    }
    else
    {
    double heightScale = ((double)componentWidth) / ((double)
    imageWidth);
    int scaledHeight = (int)(((double)imageHeight) *
    heightScale);
    double widthScale = ((double)componentHeight) / ((double)
    imageHeight);
    int scaledWidth = (int)(((double)imageWidth) * widthScale);
    if ( scaledWidth <= componentWidth ) scale = widthScale;
    else scale = heightScale;
    }

    // Now create thumbnail
    AffineTransform affineTransform = AffineTransform.getScaleInstance
    (scale,scale);
    AffineTransformOp affineTransformOp = new AffineTransformOp
    (affineTransform,null);
    BufferedImage scaledBufferedImage = affineTransformOp.filter
    (bufferedImage,null);

    int scaledWidth = scaledBufferedImage.getWidth();
    int scaledHeight = scaledBufferedImage.getHeight();

    int expectedWidth = (int)(imageWidth * scale);
    int expectedHeight = (int)(imageHeight * scale);
    if ( scaledWidth > expectedWidth || scaledHeight > expectedHeight )
    scaledBufferedImage = scaledBufferedImage.getSubimage
    (0,0,expectedWidth,expectedHeight);

    // Now write out scaled image to file
    ImageIO.write(scaledBufferedImage,"JPG",new File(destFileName));
    }


    public static void main(String[] args)
    {
    try
    {
    int size = 800;
    //size = Integer.parseInt(args[2]);
    String cart;
    cart = args[0];
    File f = new File(cart);
    String list[] = f.list();
    for (int i = 0; i < list.length; i++)
    ---> JPGImage jpgImage = new JPGImage(list[i],list[i],size);
    }
    catch (Exception exception)
    {
    System.out.println("Attenzione errore:" + exception);
    }
    }// fine main
    }
    Alla riga contrassegnata in rosso in fase di compilazione mi dice:
    not a statement.Qualche suggerimento?
    grazie
    Think ahead, think linux!

  2. #2
    Utente di HTML.it L'avatar di MMarzia
    Registrato dal
    Mar 2001
    Messaggi
    1,781
    percky, il linguaggio va specificato anche nel titolo, come da regolamento


    per rendere il codice più leggibile includilo nel tag [*code] [/*code] (senza asterischi)
    io sono festosamente cicciottello :: e. cartman

    t'amo senza sapere come, nè quando nè da dove,
    t'amo direttamente senza problemi nè orgoglio:
    così ti amo perchè non so amare altrimenti

  3. #3
    Utente di HTML.it L'avatar di percky
    Registrato dal
    May 2001
    Messaggi
    118
    OK scusate modifico il titolo appena posibile
    Think ahead, think linux!

  4. #4
    prova un pò così:
    codice:
    JPGImage jpgImage;
    jpgImage = new JPGImage[list.length - 1];
    for (int i = 0; i < list.length; i++) 
      jpgImage[i] = new JPGImage(list[i],list[i],size);
    fammi sapere
    www.matteosteri.it

  5. #5
    Utente di HTML.it L'avatar di percky
    Registrato dal
    May 2001
    Messaggi
    118
    Grazie per la dritta; il codice che mi hai scritto mi dava qualche problema in fase di compilazione che no risolto in questo modo:


    codice:
    JPGImage jpgImage;
    int i = 0;
      for (i = 0; i < list.length; i++)
      jpgImage = new JPGImage(list[i],list[i],size);
    Adesso funziona alla perfezione .....tante grazie!!!
    Think ahead, think linux!

  6. #6
    Sono andato ad intuito non l'ho provato!
    comunque l'hai risolto!

    ciao
    www.matteosteri.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.