jxl貌似只支持png格式 ,现在我本地的都是jpg格式的图片,怎么在程序中转化后直接输出到excel中啊 ,代码越短越好

解决方案 »

  1.   

    BufferedImage img = ImageIO.read(jpg文件);
    ImageIO.write(img, "png", png文件);
      

  2.   

    你调用
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, "png", baos);
    这样不会生成文件
      

  3.   

    jxl image的三种构造方法是
    WritableImage(double x, double y, double width, double height, byte[] imageData) 
              Constructor 
    WritableImage(double x, double y, double width, double height, java.io.File image) 
              Constructor 
    WritableImage(jxl.biff.drawing.DrawingGroupObject d, jxl.biff.drawing.DrawingGroup dg) 
              Constructor, used when copying sheets 在不生成文件的情况下,应该只能用第一种吧, 能详细点吗ImageIO.write(img, "png", baos)后  怎么获得转化后的图片 byte[]
      

  4.   

    直接查一下JDK的API
    ByteArrayOutputStream 的 toByteArray() --> byte[]虽然我不是黄石公,但愿你是张子房
      

  5.   

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] bytes=baos.toByteArray();
    ImageIO.write(bufimage, "png", baos);但插入到excel的时候还是挂了 显示个叉  如果ImageIO.write(bufimage,"png", new File("d:aa.png"))
    导出到硬盘 在读入 显示是正常的。。