導航:首頁 > 編程語言 > 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圖片資料庫二進制相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:612
php5314 瀏覽:352
完美國際安裝到哪個文件夾 瀏覽:664
什麼app可以掃一掃做題 瀏覽:535
程序員編碼論壇 瀏覽:921
淘點是什麼app 瀏覽:656
中國高等植物pdf 瀏覽:451
51單片機時間 瀏覽:179
後台如何獲取伺服器ip 瀏覽:262
單片機流水燈程序c語言 瀏覽:230
程序員第二職業掙錢 瀏覽:237
運行里怎麼輸入伺服器路徑 瀏覽:835
pythonstepwise 瀏覽:506
劉一男詞彙速記指南pdf 瀏覽:59
php認證級別 瀏覽:364
方舟編譯啥時候推送 瀏覽:1007
php手機驗證碼生成 瀏覽:672
哲學思維pdf 瀏覽:13
凌達壓縮機有限公司招聘 瀏覽:531
weblogic命令部署 瀏覽:33