導航:首頁 > 文件目錄 > java圖片文件流

java圖片文件流

發布時間:2023-08-29 05:56:04

⑴ 怎麼用java文件中讀取圖片和寫入圖片到文件里

首先導入各種需要的包:
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;
讀取圖片的方法如下:
Image[] array = new Image[10];
Image image = ImageIO.read(new File("d:\\source.gif"));//根據你實際情況改文件路徑吧
array[0] = image;
圖片讀出來了。

如果你有一個Image對象,想把它寫入文件可以這樣做:
BufferedImage image = ImageIO.read(new File("d:\\source.gif"));
//要想保存這個對象的話你要把image聲明為BufferedImage 類型
ImageIO.write(image, "png", new File("f:\\test.png"));

⑵ java如何傳輸動態圖片(GIF圖片)

實現思路:無論是何種類型,都是轉換為流的形式進行的文件傳輸和存儲。
可以通過BufferedReader 流的形式進行流緩存,之後通過readLine方法獲取到緩存的內容。
BufferedReader bre = null;
OutputStreamWriter pw = null;//定義一個流
try {
String file = "D:/test/test.GIF";
bre = new BufferedReader(new FileReader(file));//此時獲取到的bre就是整個文件的緩存流
pw = new OutputStreamWriter(new FileOutputStream(「D:/New.GIF」),"GBK");//確認流的輸出文件和編碼格式,此過程創建了「test.GIF」實例
while ((str = bre.readLine())!= null) // 判斷最後一行不存在,為空結束循環
{
pw.write(str);//將要寫入文件的內容,可以多次write
};
bre.close();
pw.close();//關閉流
備註:文件流用完之後必須及時通過close方法關閉,否則會一直處於打開狀態,直至程序停止,增加系統負擔。

⑶ Java中如何把圖片轉換成二進制流

使用java的IO流對圖片進行二進制讀取操作即可

示例為:讀取圖片為二進制流,並寫入到其他圖片中

staticvoidtestCopyImage(){
Filesource=newFile("E:\share\Wallpaper\Bliss.jpg");
Filedesk=newFile("d:\images");
if(!desk.exists()){
desk.mkdir();
}

try{
FileInputStreaminputStream=newFileInputStream(source);
FileOutputStreamoutputStream=newFileOutputStream(newFile("d:/images/Bliss.jpg"));

intch=inputStream.read();
while(ch!=-1){
outputStream.write(ch);
ch=inputStream.read();
}

inputStream.close();
outputStream.close();
System.out.println("圖片復製成功!");
}catch(FileNotFoundExceptione){
System.out.println("文件不存在:"+e.getMessage());
}catch(IOExceptione){
System.out.println("文件讀取錯誤:"+e.getMessage());
}

}

⑷ java把圖片轉換成二進制流

public static void main(String[] args) throws Exception {

File file = new File("d:\L.jpg");//圖片

FileInputStream fis = new FileInputStream(file);//把圖片變成流

FileOutputStream fos = new FileOutputStream(new File("E:\L.jpg")); //把圖片流寫入E盤

byte[] read = new byte[1024]; //每次讀取的字版節 可以自己定義權 256 512 1024 2048 等。。。

int len = 0;

while((len = fis.read(read))!= -1){ //讀取變成流的圖片

fos.write(read,0,len);//寫入圖片

}

fis.close();//關閉輸入流

fos.close();//關閉輸出流

}

閱讀全文

與java圖片文件流相關的資料

熱點內容
計算機痕跡擦除工具 瀏覽:878
qq易貸是正規公司嗎 瀏覽:228
目前取流行的編程語言有哪些 瀏覽:994
tar解壓工具 瀏覽:240
黃埔網路安全建設有哪些 瀏覽:877
php如何操作資料庫 瀏覽:701
微賺網站 瀏覽:510
數控機床常用的編程方法有哪些 瀏覽:467
鐵路與大數據分析產生什麼結果 瀏覽:572
如何把文件轉為種子 瀏覽:59
玩股票杠桿用什麼app 瀏覽:999
怎麼用q幣充qq紅包 瀏覽:140
海外代購app哪個比較好 瀏覽:729
手機改qq密碼怎麼改 瀏覽:238
api壓縮文件夾 瀏覽:847
網路營銷中營銷策略都有哪些 瀏覽:926
mat格式文件數據類型 瀏覽:132
手機文件刪除如何恢復 瀏覽:682
如何計算帶有指數的數據 瀏覽:243
手機數據存儲在主板的哪裡 瀏覽:151

友情鏈接