氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          JAVA讀取EMF文件并轉化為PNG,JPG,GIF格式

          JAVA讀取EMF文件并轉化為PNG,JPG,GIF格式
          使用第三方庫下載地址為:http://java.freehep.org/vectorgraphics/index.html
          主要思路:
          使用EMFInputStream讀取EMF文件,然后使用EMFRenderer對象將EMF繪制到創建
          好的空白的BufferedImage里面。這樣就把EMF圖片轉化為Java中的BufferedImage對
          象,然后可以重新保存為Java 2D支持圖像格式如PNG或者JPG等。
           
          代碼如下:
          [java] view plaincopy
          import java.awt.BorderLayout;  
          import java.awt.Dimension;  
          import java.awt.Graphics;  
          import java.awt.Graphics2D;  
          import java.awt.image.BufferedImage;  
          import java.io.File;  
          import java.io.FileInputStream;  
          import java.io.FileNotFoundException;  
          import java.io.IOException;  
            
          import javax.imageio.ImageIO;  
          import javax.swing.JFrame;  
          import javax.swing.JPanel;  
            
          import org.freehep.graphicsio.emf.EMFInputStream;  
          import org.freehep.graphicsio.emf.EMFRenderer;  
          /** 
           * download the third-party libraries here: 
           * http://java.freehep.org/vectorgraphics/index.html 
           *  
           * @author gloomyfish 
           * 
           */  
          public class EMFReader {  
              public static void main(String[] args) {  
                  try {  
                      EMFInputStream inputStream = new EMFInputStream(new FileInputStream("D:\\export.emf"), EMFInputStream.DEFAULT_VERSION);  
                      System.out.println("height = " + inputStream.readHeader().getBounds().getHeight());  
                      System.out.println("widht = " + inputStream.readHeader().getBounds().getWidth());  
                        
                      // headerInfo of bitmap API always tell a lie, could not get   
                      // correct width and height  
                      // BitmapInfoHeader headerInfo = new BitmapInfoHeader(inputStream);  
                      // System.out.println("Big Error on reading emf format picture");  
                      EMFRenderer emfRenderer = new EMFRenderer(inputStream);  
                        
                      // create buffered image object from EMF render  
                      final int width = (int)inputStream.readHeader().getBounds().getWidth();  
                      final int height = (int)inputStream.readHeader().getBounds().getHeight();  
                      System.out.println("widht = " + width + " and height = " + height);  
                      final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);  
                      Graphics2D g2 = (Graphics2D)result.createGraphics();  
                      emfRenderer.paint(g2);  
                        
                      // write it as png/jpg/gif, up to you!!!  
                      File outputfile = new File("D:\\result.png");  
                      ImageIO.write(result, "png", outputfile);  
            
                      // display it   www.heatpress123.net
                      JPanel resultPanel = new JPanel() {  
                          /** 
                           *  
                           */  
                          private static final long serialVersionUID = 1L;  
                          public void paintComponent(Graphics g) {  
                              super.paintChildren(g);  
                              Graphics2D g2 = (Graphics2D)g;  
                              g2.drawImage(result, 0, 0, width, height, null);  
                          }  
                      };  
                      JFrame ui = new JFrame("EMF Reader");  
                      ui.getContentPane().setLayout(new BorderLayout());  
                      ui.getContentPane().add(resultPanel, BorderLayout.CENTER);  
                      ui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                      ui.setSize(new Dimension(width+20, height+40));  
                      ui.setVisible(true);  
                  } catch (FileNotFoundException e) {  
                      e.printStackTrace();  
                  } catch (IOException e) {  
                      e.printStackTrace();  
                  }  
              }  
          }  
          原文:http://www.software8.co/wzjs/java/1416.html

          posted on 2012-11-23 10:00 你爸是李剛 閱讀(1891) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2012年11月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 京山县| 宜昌市| 青浦区| 临高县| 广昌县| 工布江达县| 大姚县| 临猗县| 松滋市| 寿阳县| 鸡东县| 永济市| 望都县| 电白县| 永康市| 盐边县| 社旗县| 新密市| 邵武市| 鱼台县| 郯城县| 孝义市| 桃园市| 白玉县| 翼城县| 邻水| 闽侯县| 修文县| 佳木斯市| 武山县| 鱼台县| 金坛市| 枣庄市| 峨山| 广汉市| 澳门| 上栗县| 朝阳县| 清涧县| 轮台县| 奈曼旗|