将image对象转成BufferedImage
生活随笔
收集整理的這篇文章主要介紹了
将image对象转成BufferedImage
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/*** 將image對象 轉(zhuǎn)成 BufferedImage** @param image* @return*/private BufferedImage toBufferedImage(Image image) {if (image instanceof BufferedImage) {return (BufferedImage) image;}image = new ImageIcon(image).getImage();BufferedImage bimage = null;GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();try {int transparency = Transparency.OPAQUE;GraphicsDevice gs = ge.getDefaultScreenDevice();GraphicsConfiguration gc = gs.getDefaultConfiguration();bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);} catch (HeadlessException e) {//........}if (bimage == null) {int type = BufferedImage.TYPE_INT_RGB;bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);}Graphics g = bimage.createGraphics();g.drawImage(image, 0, 0, null);g.dispose();return bimage;}
?
總結(jié)
以上是生活随笔為你收集整理的将image对象转成BufferedImage的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最新h5微信大灌篮小游戏投篮赚钱源码+手
- 下一篇: 真香啊,一文讲透金融风控建模全流程(Py