日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

emf java_Java实现emf图片字节流转png(jpg)图片字节流

發(fā)布時間:2025/3/20 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 emf java_Java实现emf图片字节流转png(jpg)图片字节流 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

private byte[] emfToPng(InputStream is){//InputStream inputStream=null;

byte[] by=null;

EMFInputStream emf= null;

EMFRenderer emfRenderer= null;//創(chuàng)建儲存圖片二進制流的輸出流

ByteArrayOutputStream baos = null;//創(chuàng)建ImageOutputStream流

ImageOutputStream imageOutputStream = null;try{

emf= newEMFInputStream(is, EMFInputStream.DEFAULT_VERSION);

emfRenderer= newEMFRenderer(emf);final int width = (int)emf.readHeader().getBounds().getWidth();final int height = (int)emf.readHeader().getBounds().getHeight();final BufferedImage result = newBufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2=(Graphics2D)result.createGraphics();

emfRenderer.paint(g2);//創(chuàng)建儲存圖片二進制流的輸出流

baos = newByteArrayOutputStream();//創(chuàng)建ImageOutputStream流

imageOutputStream =ImageIO.createImageOutputStream(baos);//將二進制數(shù)據(jù)寫進ByteArrayOutputStream

ImageIO.write(result, "png", imageOutputStream);//inputStream = new ByteArrayInputStream(baos.toByteArray());

by=baos.toByteArray();/*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);

g2.dispose();

}

};

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, height));

ui.setVisible(true);*/}catch(FileNotFoundException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}finally{try{if(imageOutputStream!=null){

imageOutputStream.close();

}if(baos!=null){

baos.close();

}if(emfRenderer!=null){

emfRenderer.closeFigure();

}if(emf!=null){

emf.close();

}

}catch(IOException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}returnby;

}

總結(jié)

以上是生活随笔為你收集整理的emf java_Java实现emf图片字节流转png(jpg)图片字节流的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。