在doc模式下,程序可以生成jpg个png格式,但太小了,才300多B,生成的bmp格式的图片为空。
用Myeclipse生成bmp格式图片,挺大的,有18K。
该怎么设置下,使doc模式下生成的bmp格式图片不为空?

解决方案 »

  1.   

      import   java.awt.image.BufferedImage;   
      import   javax.imageio.ImageIO;   
      import   java.io.*;   
        
      public   class   jpgtobmp   {   
        
        
          public   static   boolean   converted(String   sourceFile,   String   targetFile)   {   
              boolean   isSuccess   =   false;   
              try   {   
                  FileInputStream   in   =   new   FileInputStream(sourceFile);   
                  File   jpg   =   new   File(targetFile);   
                  BufferedImage   image   =   ImageIO.read(in);   
                  isSuccess   =   ImageIO.write(image,   "BMP",   jpg);   
                  isSuccess   =   true;   
                  image.flush();   
                  in.close();   
              }   
              catch   (IOException   ex)   {   
        
              }   
              return   isSuccess;   
        
          }   
        
          public   static   void   main(String[]   args)   {   
              boolean   a   =   converted("c:/convert/1.jpg",   "c:/convert/1.bmp");   
          }   
        
      }这段代码和我的差不多,把write方法中的参数“BMP”改成“JPG”可以,但BMP生成的为空?该怎么解决?~
      

  2.   

    FileInputStream in = new FileInputStream(sourceFile);   
    换成
    FileInputStream in = new FileInputStream( new File(sourceFile));看下   
      

  3.   

    算了,还是看我的源码吧!~在doc模式下传入俩参数,生成bmp格式的图片!~不能用Myeclipse!~~package test;import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import javax.imageio.ImageIO;
    import com.swetake.util.Qrcode;
    public class QRCode {
    public static void main(String[] args) throws Exception{
    // TODO Auto-generated method stub
    Qrcode qrcode=new Qrcode();   
             qrcode.setQrcodeErrorCorrect('L');   
                    qrcode.setQrcodeEncodeMode('B');   
            qrcode.setQrcodeVersion(1);  
             //System.out.println("please input a word:");
             //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
             //String testString = br.readLine();
             String testString = args[0];   
            
            byte[] d =testString.getBytes("UTF-8");   
             BufferedImage bi = new BufferedImage(67, 67, BufferedImage.TYPE_INT_RGB);   
             // createGraphics   
             Graphics2D g = bi.createGraphics();   
             // set background   
             g.setBackground(Color.WHITE);   
             g.clearRect(0, 0, 139, 139);   
             g.setColor(Color.BLACK);   
             if (d.length>0 && d.length <123){   
                 boolean[][] b = qrcode.calQrcode(d);   
                 for (int i=0;i<b.length;i++){   
                        for (int j=0;j<b.length;j++){   
                         if (b[j][i]) {   
                                g.fillRect(j*3+2,i*3+2,3,3);   
                         }   
                        }   
                 }   
                 }         
             g.dispose();   
             bi.flush();    
    String FilePath="D:\\"+args[1];
             File f = new File(FilePath);   
               
             ImageIO.write(bi, "bmp", f);   
             //System.out.println("doned!");   
        }   
    }
      

  4.   

    怎么修改上面的代码,使能生成BMP格式的图片,最好还能让图片大点!~
    求高手给出正解!~~