導航:首頁 > 編程語言 > java讀取jpg

java讀取jpg

發布時間:2022-05-24 13:10:30

『壹』 java將 jpg圖像數據讀出來,並用十六進制方式顯示在文本文件中

使用ByteArrayInputStream將文件讀出來,然後轉成byte數組,然後將數組的每一成員轉成十六進制輸出就好了

『貳』 請教如何用Java語言讀取jpg圖片,並顯示

1、獲取文件夾的路徑 2、得到文件夾中的有圖片的名稱,可以存到數組或者集合中 3、你再到jsp頁面做顯示, 4、下面是獲取路徑和文件名的代碼,前台顯示的代碼自己寫 String path = 文件夾路徑; String names = ""; try { File f = new File(path)

『叄』 java imageIO 讀取圖片問題

試了一下,這張jpg圖片中含有大量的元數據(註解數據),結構復雜,導致java讀取錯誤。
可用畫圖等圖片編輯軟體「另存為」或者「導出」一下,同時去掉元數據。
就可以被ImageIO讀取

『肆』 怎麼用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 怎樣從磁碟讀取圖片文件

用JFileChoose 這個類,用來選擇文件 主要代碼如下:
JFileChooser f = new JFileChooser(); // 查找文件
f.setFileFilter(new FileNameExtensionFilter("圖片文件(*.bmp, *.gif, *.jpg, *.jpeg, *.png)", "bmp", "gif","jpg", "jpeg", "png"));
int rVal = f.showOpenDialog(null);

『陸』 java怎麼限制只能從資料庫中讀取.jpg文件

讀寫是兩個不同的分支,通常都是分開單獨使用的,但是原則就是什麼文件的流就要用相應的流進行存儲。
可以通過BufferedReader 流的形式進行流緩存,之後通過readLine方法獲取到緩存的內容。
BufferedReader bre = null;
try {
String file = "D:/test/test.png";
bre = new BufferedReader(new FileReader(file));//此時獲取到的bre就是整個文件的緩存流
while ((str = bre.readLine())!= null) // 判斷最後一行不存在,為空結束循環
{
System.out.println(str);//原樣輸出讀到的內容
};
備註: 流用完之後必須close掉,如上面的就應該是:bre.close(),否則bre流會一直存在,直到程序運行結束。
可以通過「FileOutputStream」創建文件實例,之後過「OutputStreamWriter」流的形式進行存儲,舉例:
OutputStreamWriter pw = null;//定義一個流
pw = new OutputStreamWriter(new FileOutputStream(「D:/test.png」),"GBK");//確認流的輸出文件和編碼格式,此過程創建了「test.txt」實例
pw.write("我是要寫入到記事本文件的內容");//將要寫入文件的內容,可以多次write
pw.close();//關閉流
備註:文件流用完之後必須及時通過close方法關閉,否則會一直處於打開狀態,直至程序停止,增加系統負擔。

『柒』 Java如何讀取文件夾中所有圖片,並顯示出來

說一下思路吧,首先遍歷文件夾,找到對應後綴的文件(png,jpg之類的),然後創建Bitmap對象,使用inputStream將文件轉成bitmap對象,之後使用imageview或者GLview顯示圖片即可。
注意對大圖進行壓縮,結束時圖片必須回收處理,bitmap.recycle()否則圖片多了內存溢出

『捌』 java或者js有沒有讀取.jpg的DPI的方法 求例子

DPI信息在jpg文件中用5個位元組表示,直接讀取二進制流就可以了

偏移 13 的1個位元組:
X和Y的密度單位
units=0:無單位
units=1:點數/英寸
units=2:點數/厘米

偏移15的2位元組:
水平方向像素密度

偏移16的2位元組:
垂直方向像素密度

『玖』 用java怎麼讀取圖片

思路:使用 java.awt.Image包下的Image可以接收圖片。讀取則使用ImageIO對象。

代碼如下:

/**
* 讀取圖片,首先導入以下的包
*/
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;

/**
* 用Image對象來接收圖片
* 路徑根據實際情況修改
*/
Image image = ImageIO.read(new File("c:\\1.png"));
System.out.println(image.getSource());

『拾』 用java實現讀取一個jpg圖片,根據4個坐標,把坐標內的圖片保存為另一個jpg圖片

packagetest.any;

importjava.awt.Rectangle;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.util.Iterator;
importjavax.imageio.ImageIO;
importjavax.imageio.ImageReadParam;
importjavax.imageio.ImageReader;
importjavax.imageio.stream.ImageInputStream;
publicclassCutPicture{
privateStringsrcpath;
privateStringsubpath;
privateStringimageType;
privateintx;
privateinty;
privateintwidth;
privateintheight;
publicCutPicture(){
}

publicCutPicture(Stringsrcpath,intx,inty,intwidth,intheight){
this.srcpath=srcpath;
this.x=x;
this.y=y;
this.width=width;
this.height=height;
}
publicintgetHeight(){
returnheight;
}
publicvoidsetHeight(intheight){
this.height=height;
}
publicStringgetSrcpath(){
returnsrcpath;
}
publicvoidsetSrcpath(Stringsrcpath){
this.srcpath=srcpath;
if(srcpath!=null){
this.imageType=srcpath.substring(srcpath.indexOf(".")+1,srcpath.length());
}
}
publicStringgetSubpath(){
returnsubpath;
}
publicvoidsetSubpath(Stringsubpath){
this.subpath=subpath;
}
publicintgetWidth(){
returnwidth;
}
publicvoidsetWidth(intwidth){
this.width=width;
}
publicintgetX(){
returnx;
}
publicvoidsetX(intx){
this.x=x;
}
publicintgetY(){
returny;
}
publicvoidsetY(inty){
this.y=y;
}

publicStringgetImageType(){
returnimageType;
}
publicvoidsetImageType(StringimageType){
this.imageType=imageType;
}

publicvoidcut()throwsIOException{
FileInputStreamis=null;
ImageInputStreamiis=null;
try{
is=newFileInputStream(srcpath);
this.setSrcpath(srcpath);
Iterator<ImageReader>it=ImageIO.getImageReadersByFormatName(this.imageType);
ImageReaderreader=it.next();
iis=ImageIO.createImageInputStream(is);
reader.setInput(iis,true);
ImageReadParamparam=reader.getDefaultReadParam();
Rectanglerect=newRectangle(x,y,width,height);
param.setSourceRegion(rect);
BufferedImagebi=reader.read(0,param);
ImageIO.write(bi,this.imageType,newFile(subpath));
}finally{
if(is!=null)
is.close();
if(iis!=null)
iis.close();
}
}

publicstaticvoidmain(String[]args){
CutPictureo=newCutPicture("c:\粗切編目層詳細1.png",0,0,100,100);
o.setSubpath("c:\1.png");
try{
o.cut();
}catch(IOExceptione){
e.printStackTrace();
}
}
}

閱讀全文

與java讀取jpg相關的資料

熱點內容
台達PLC編譯按鈕在哪裡 瀏覽:137
非編程計算器多少錢 瀏覽:653
房本還完貸款解壓 瀏覽:816
中國程序員有出名嗎 瀏覽:546
亳州雲伺服器 瀏覽:630
程序員最難的面試 瀏覽:892
配音秀app怎麼誦讀 瀏覽:750
sparkcore源碼 瀏覽:100
程序員中年生活 瀏覽:355
讀取加密信息失敗怎麼回事 瀏覽:510
編譯過程之後是預處理嗎 瀏覽:351
安卓是基於什麼做出來 瀏覽:600
視頻字幕提取APP怎麼使用 瀏覽:59
js通過ip地址連接伺服器嗎 瀏覽:848
java數字金額大寫金額 瀏覽:858
人人影視路由器固件編譯 瀏覽:967
照片通訊錄簡訊怎麼從安卓到蘋果 瀏覽:458
邏輯開發編譯環境 瀏覽:672
ce自己編譯 瀏覽:898
javaexe進程 瀏覽:478