91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 6KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-06
  • 語言: Java
  • 標(biāo)簽: Java??

資源簡介

java 實(shí)現(xiàn)十六進(jìn)制數(shù)轉(zhuǎn)為圖片實(shí)例,含代碼和測試數(shù)據(jù)

資源截圖

代碼片段和文件信息

package?com.mybatis.test;

import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileOutputStream;

public?class?TestImage1?{

public?static?void?main(String[]?args)?throws?Exception?{
/* byte[]?b1?=image2Bytes(“d:\\1.jpg“);
// for(int?i=0;i System.out.println();
FileOutputStream?fos=new?FileOutputStream(“d:\\image.txt“);
fos.write(b1);
fos.close();*/

FileInputStream?fis=new?FileInputStream(new?File(“d:\\data.txt“));
char[]?ch=new?char[fis.available()];
System.out.println(fis.available());
int?len=fis.available();
int?j=0;
System.out.println();
for(int?i=0;i int?temp=fis.read();
char?c=(char)temp;
if(temp!=32){
ch[j++]=c;
// System.out.print(c);
}
}
System.out.println();

System.out.println(new?String(ch0j).length());
byte[]?b=hexStringToBytes(new?String(ch0j));
buff2Image(b“d:\\test.jpeg“);
fis.close();

}

?
static?void?buff2Image(byte[]?bString?tagSrc)?throws?Exception
????{
????????FileOutputStream?fout?=?new?FileOutputStream(tagSrc);
????????//將字節(jié)寫入文件
????????fout.write(b);
????????fout.close();
????}
public?static?byte[]?hexStringToBytes(String?hexString)?{??
????if?(hexString?==?null?||?hexString.equals(““))?{??
????????return?null;??
????}??
????hexString?=?hexString.toUpperCase();??
????int?length?=?hexString.length()?/?2;??
????char[]?hexChars?=?hexString.toCharArray();??
????byte[]?d?=?new?byte[length];??
????for?(int?i?=?0;?i? ????????int?pos?=?i?*?2;??
????????d[i]?=?(byte)?(charToByte(hexChars[pos])?< ????}??
????return?d;??
}??
?private?static?byte?charToByte(char?c)?{??
????return?(byte)?“0123456789ABCDEF“.indexOf(c);??
}

static?byte[]?image2Bytes(String?imgSrc)?throws?Exception
????{
????????FileInputStream?fin?=?new?FileInputStream(new?File(imgSrc));
????????//可能溢出簡單起見就不考慮太多如果太大就要另外想辦法,比如一次傳入固定長度byte[]
????????byte[]?bytes??=?new?byte[fin.available()];
????????//將文件內(nèi)容寫入字節(jié)數(shù)組,提供測試的case
????????fin.read(bytes);
????????fin.close();
????????return?bytes;
????}
public?static?String?hexString2binaryString(String?hexString)??
????{??
????????if?(hexString?==?null?||?hexString.length()?%?2?!=?0)??
????????????return?null;??
????????String?bString?=?““?tmp;??
????????for?(int?i?=?0;?i?????????{??
????????????tmp?=?“0000“??
????????????????????+?Integer.toBinaryString(Integer.parseInt(hexString??
????????????????????????????.substring(i?i?+?1)?16));??
????????????bString?+=?tmp.substring(tmp.length()?-?4);??
????????}??
????????return?bString;??
}

public?static?String?binaryString2hexString(String?bString)??
????{??
????????if?(bString?==?null?||?bString.equals(““)?||?bString.length()?%?8?!=?0)??
????????????return?null;??
????????StringBuffer?tmp?=?new?StringBuffer();??
????????i

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????11600??2016-01-09?15:34??data.txt

?????文件???????3458??2016-01-09?20:08??TestImage1.java

-----------?---------??----------?-----??----

????????????????15058????????????????????2


評論

共有 條評論