導航:首頁 > 編程語言 > java圖片資料庫二進制

java圖片資料庫二進制

發布時間:2023-10-31 23:34:19

java 二維碼圖片轉二進制存進資料庫 使用什麼技術可以實現呢

  1. 資料庫使用blob類型

  2. 圖片使用java io流操作,將圖片轉換為byte[],存入mysql中

❷ java 資料庫中2進制流image轉成pdf

FileUtils.writeByteArrayToFile(new File("xx.pdf"),p.getBytes());

一般存到資料庫的二進制流都是經過加密的,常用的是base64
byte[]bytes = new BASE64Decoder().decodeBuffer(p);
FileUtils.writeByteArrayToFile(new File("xx.pdf"),bytes);

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

Java中將圖片轉為二進制流只需要使用FileImageInputStream取得圖片文件,然後使用ByteArrayOutputStream 寫入到二進制流中即可,下面是詳細代碼:


//圖片到byte數組
publicbyte[]image2byte(Stringpath){
byte[]data=null;
FileImageInputStreaminput=null;
try{
input=newFileImageInputStream(newFile(path));
ByteArrayOutputStreamoutput=newByteArrayOutputStream();
byte[]buf=newbyte[1024];
intnumBytesRead=0;
while((numBytesRead=input.read(buf))!=-1){
output.write(buf,0,numBytesRead);
}
data=output.toByteArray();
output.close();
input.close();
}
catch(FileNotFoundExceptionex1){
ex1.printStackTrace();
}
catch(IOExceptionex1){
ex1.printStackTrace();
}
returndata;
}

另外,如果需要將byte[]存回圖片或轉為String,則:

//byte數組到圖片
publicvoidbyte2image(byte[]data,Stringpath){
if(data.length<3||path.equals(""))return;
try{
=newFileImageOutputStream(newFile(path));
imageOutput.write(data,0,data.length);
imageOutput.close();
System.out.println("MakePicturesuccess,Pleasefindimagein"+path);
}catch(Exceptionex){
System.out.println("Exception:"+ex);
ex.printStackTrace();
}
}
//byte數組到16進制字元串
publicStringbyte2string(byte[]data){
if(data==null||data.length<=1)return"0x";
if(data.length>200000)return"0x";
StringBuffersb=newStringBuffer();
intbuf[]=newint[data.length];
//byte數組轉化成十進制
for(intk=0;k<data.length;k++){
buf[k]=data[k]<0?(data[k]+256):(data[k]);
}
//十進制轉化成十六進制
for(intk=0;k<buf.length;k++){
if(buf[k]<16)sb.append("0"+Integer.toHexString(buf[k]));
elsesb.append(Integer.toHexString(buf[k]));
}
return"0x"+sb.toString().toUpperCase();
}

❹ java如何存儲圖片到資料庫,存路徑和二進制是什麼意思

一種方法是把圖像文件本身放在某個文件夾里,然後在數據表裡設一個「路徑「欄位,類型為字元串,存圖像的路徑(比如「D:\files\xxx.jpg」)。
另一種方法是,把圖像文件本身,作為一個巨大的二進制數據,放在資料庫中;具體方法是,數據表中設置一個」數據「欄位,類型是二進制數據,存放圖像本體。

閱讀全文

與java圖片資料庫二進制相關的資料

熱點內容
字幕網app怎麼找 瀏覽:527
奧迪a4l壓縮比 瀏覽:692
iis7伺服器怎麼安裝 瀏覽:974
孩子上學壓力太大怎麼解壓 瀏覽:235
javaurl格式 瀏覽:341
勻稱app怎麼用 瀏覽:60
pythonemail中文亂碼 瀏覽:441
android訪問html 瀏覽:87
做一個app或者網頁用什麼編程 瀏覽:775
一體機伺服器運行失敗怎麼辦 瀏覽:935
longjava比較大小 瀏覽:530
clojure編程pdf 瀏覽:21
一年級數學圈一圈的演算法 瀏覽:110
完整的python 瀏覽:41
c51單片機數字鍾 瀏覽:922
apk文件反編譯後安裝包損壞 瀏覽:815
app圖標分別是什麼 瀏覽:367
linux全選命令 瀏覽:365
怎麼用華碩app 瀏覽:962
小明台灣通道加密 瀏覽:375