image java
- IT科技
- 關注:3.13W次
<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
java image是什麼,讓我們一起了解一下?
Image主要是實現讀取圖片檔案(Image.FromFile)和儲存影象檔案(Image.Save)。只要將圖片轉為Image類之後,就可以用.Net裡面強大的GDI+功能,但GDI+必須先要建立Graphics。
那麼如何建立Image影象?
1、通過檔案選擇器選擇檔案,建立File檔案,建立Image影象。
Image images = new Image(); JFileChooser chooser = new JFileChooser(); chooser.setName("選擇"); chooser.setMultiSelectionEnabled(false); //設定檔案選擇器只能選擇單個檔案 int result = chooser.showOpenDialog(this); //開啟檔案選擇器 if(result == JFileChooser.APPROVE_OPTION){ File file = chooser.getSelectedFile(); try{ //對異常進行處理 images = ImageIO.read(file); }catch(IOException e){ e.printStackTrace(); } }
2、通過Toolkit工具中的函式建立Image影象。
Image images = new Image();Toolkit tool = Toolkit.getDefaultToolkit();images = tool.getImage("1.gif");//字串為絕對路徑或相對路徑
- 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/mmp62n.html