1.一个图像的大小的为:100*100  格式为jpg
要把它变为32*32大小作为图标在组件里显示出来,比如在JLable里显示出来,可何实现?
2.如何实现像Windows文件浏览器一样显示大图标、小图标、列表、详细信息?用哪个组件?答完散分,谢谢!

解决方案 »

  1.   

    /**
       * 等比例缩放图像, 本方法目前支持三个图片格式jpg, gif, png, 所有生成都被转化为jpg
       *fullname  图片路径
       * path     目标路径(不带文件名)
       *prtfix    生成的文件名的前缀
       *photomaxw         文件宽度范围
       *photomaxh         文件高度范围
       */
      public static String getSmallJpg(String fullname, String path, String prefix,
                                       float photomaxw, float photomaxh) throws
          Exception {
        File filePath = null;
        try {
          File file = new File(fullname); //读入文件
          if (!file.exists()) {
            return null;
          }
          else {
            //上传flash
            if (fullname.endsWith("swf")) {
              String fileName = file.getName();
              String filePiexName = FileUtil.getFilePrefixName(fileName);
              String newPmgPath = path + "/" + prefix + "_" + filePiexName + ".swf";
              FileUtil.copyFile(fullname, newPmgPath);
              File newFile = new File(newPmgPath);
              return newFile.getName();
            }
          }      Image src = javax.imageio.ImageIO.read(file); //构造Image对象
          //  System.out.println("压缩文件名:" + "   " + file.getAbsoluteFile() );
          float wideth = src.getWidth(null); //得到源图宽
          float height = src.getHeight(null); //得到源图长
          System.out.println("class = " + src.getClass());      System.out.println("源文件宽度:" + wideth + "¥"); //测试
          System.out.println("源文件高度:" + height + "¥");      if (wideth > photomaxw) {
            float mw = wideth;
            System.out.println("限制高度:" + photomaxh);
            System.out.println("限制宽度:" + photomaxw);
            wideth = photomaxw;
            height = height * photomaxw / mw;        System.out.println("收缩后的实际宽度:" + wideth + "●"); //测试
            System.out.println("收缩后的实际高度:" + height + "●");        if (height > photomaxh) {
              float mo = height;
              height = photomaxh;
              wideth = wideth * photomaxh / mo;
            }
          }
          else if (wideth < photomaxw || wideth == photomaxw) {
            float mo = height;
            if (height > photomaxh) {
              height = photomaxh;
              wideth = wideth * height / mo;
            }
          }      if (wideth == 0) {
            wideth = src.getWidth(null);
          }      if (height == 0) {
            height = src.getHeight(null);
          }      System.out.println("最终宽度:" + wideth + "●"); //测试
          System.out.println("最终高度:" + height + "●");      if (height == 0 || wideth == 0) {
            return null;
          }      BufferedImage tag = new BufferedImage( (int) wideth, (int) height,
                                                BufferedImage.TYPE_INT_RGB);
          tag.getGraphics().drawImage(src, 0, 0, (int) wideth, (int) height, null); //绘制后的图      String fileName = file.getName();      File newPmgPathDir = new File(path);
          if (!newPmgPathDir.exists() || !newPmgPathDir.isDirectory()) {
            newPmgPathDir.mkdirs();
          }      String filePiexName = FileUtil.getFilePrefixName(fileName);
          String newPmgPath = path + "/" + prefix + "_" + filePiexName + ".jpg";      FileOutputStream out = new FileOutputStream(newPmgPath); //输出到文件流
          System.out.println("getParent:" + file.getParent());
          System.out.println("getAbsoluteFile:" + file.getAbsoluteFile());
          System.out.println("getAbsolutePath:" + file.getAbsolutePath());
          System.out.println("getCanonicalFile:" + file.getCanonicalFile());
          System.out.println("getCanonicalPath:" + file.getCanonicalPath()); //有什么区别????
    ////    System.out.println("生成的文件名为:" + newPmgPath);      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
          encoder.encode(tag);
          out.close();      filePath = new File(newPmgPath); //读入文件
          System.out.println("getAbsoluteFile:" + newPmgPath);
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
        return filePath.getName();
      }
      

  2.   

    package imagesizer;import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;public class HotTest
    {    int wideth;
        int height;
        
        public HotTest()
        {
            wideth = 0;
            height = 0;
        }    public void imageSizer(File file)
        {
          String fileName = file.getName();
          try
            {
                BufferedImage bufferedimage = ImageIO.read(file);
          //把wideth和height替换成想要的尺寸就可以了
                wideth = bufferedimage.getWidth(null);
                height = bufferedimage.getHeight(null);
                BufferedImage bufferedimage1 = new BufferedImage(wideth, height, 1);
                bufferedimage1.getGraphics().drawImage(bufferedimage, 0, 0, wideth, height, null);
                FileOutputStream fileoutputstream = new FileOutputStream("./webapps/PhotoManager/photogallery/jpeg_file/jpeg_"+fileName);
                JPEGImageEncoder jpegimageencoder = JPEGCodec.createJPEGEncoder(fileoutputstream);
                jpegimageencoder.encode(bufferedimage1);
                System.out.print(wideth + ":" + height);
                fileoutputstream.close();
            }
            catch(Exception exception)
            {
                System.out.println(exception);
            }
        }}
      

  3.   

    不知道有没有组件能完成
    但通过java获取图片的名称、格式、大小、尺寸、创建时间等元数据信息及适当缩略图后入库,进行自由搭配就可以出来你所说的效果
      

  4.   

    可是我一张图片做LOGO,结果要做很多大小不同的图片,很不划算哎,还不如一次搞清楚了!