A. 大神求解 急 JAVA怎麼把16進制數 轉換成圖片
span style="font-size:14px;">package png;
import java.io.FileInputStream;
/**
* 圖片轉成十六進制
*/
public class PngBytes {
public static void main(String[] args) throws Exception {
try {
FileInputStream fis = new FileInputStream("image/1.png");
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] buff = new byte[1024];
int len = 0;
while ((len = fis.read(buff)) != -1)
B. 如何將16進制 轉換byte數組
方法/步驟
byte數組轉換成16進制字元串String:
public
class
CommonUtil
{
/**
*
byte數組轉換成16進制字元串
*
@param
src
*
@return
*/
public
static
String
bytesToHexString(byte[]
src){
StringBuilder
stringBuilder
=
new
StringBuilder();
if
(src
==
null
||
src.length
<=
0)
{
return
null;
}
for
(int
i
=
0;
i
<
src.length;
i++)
{
int
v
=
src[i]
&
0xFF;
String
hv
=
Integer.toHexString(v);
if
(hv.length()
<
2)
{
stringBuilder.append(0);
}
stringBuilder.append(hv);
}
return
stringBuilder.toString();
}
}
byte數組轉換成16進制字元數組String[]:
public
class
CommonUtil
{
/**
*
byte數組轉換成16進制字元數組
*
@param
src
*
@return
*/
public
static
String[]
bytesToHexStrings(byte[]
src){
if
(src
==
null
||
src.length
<=
0)
{
return
null;
}
String[]
str
=
new
String[src.length];
for
(int
i
=
0;
i
<
src.length;
i++)
{
int
v
=
src[i]
&
0xFF;
String
hv
=
Integer.toHexString(v);
if
(hv.length()
<
2)
{
str[i]
=
"0";
}
str[i]
=
hv;
}
return
str;
}
}
測試最終結果:
public
static
void
main(String[]
args)
{
byte[]
src
=
new
byte[]{
1,
2,
3,
4
};
System.out.println(
bytesToHexString(src)
);
System.out.println(
bytesToHexStrings(src)[2]
);
}
C. 怎麼將圖片轉換成16進制字元串
String src=...; //從資料庫取得的字元串
String output=...; //定義一個輸出流用來保存圖片
try{
FileOutputStream out = new FileOutputStream(new File(output));
byte[] bytes = src.getBytes();
for(int i=0;i< bytes.length;i+=2){
out.write(charToInt(bytes[i])*16+charToInt(bytes[i+1]));
}
out.close();
}catch(Exception e){
e.printStackTrace();
}
D. 怎麼將圖片轉換為十六進制代碼
用系統自帶的計算器就能進行轉換,你選擇16進制,輸入你要轉換的數值,然後選擇十進制即可。
2a4e
=10830
E. java如何把byte數組里的十六進制轉換成int類型,如下圖的數據,雜么轉換,跪求方法和代碼
示例
packagecom.sdvdxl.other;
publicclassTest{
publicstaticvoidmain(String[]args){
byte[]bytes=newbyte[]{0x00,0x53};
for(byteb:bytes){
System.out.println(Integer.valueOf(b));
}
}
}
結果:
0
83
PS : 使用的時候會自動轉換成10進制的
F. 請問如何把16進制數據轉換成圖片呢
很簡單,加一個文件頭、信息頭,再把數據放在後面,保存成圖片格式就成了。
G. 如何把16進制數組轉化為圖片
先轉換成BMP圖片,就是先寫好文件頭,再把數組寫到後頭
H. 怎麼將圖片轉換為十六進制代碼
讀入內存,圖片應放入一個二維數組,或一維數組,識別其高和寬,然後把讀入的數據,按16進制碼存儲
I. 圖片在資料庫里保存的是16進制數據,可以轉換為圖片嗎
CODE SEGMENT
ASSUME CS:CODE
START: push cs
pop ds
push cs
pop es
mov ah,0
int 16h
mov cx,10
mov di,offset buff_1
lp1: stosb
cmp al,3ah
jb lp2
sub al,10
lp2: inc al
loop lp1
mov dx,offset buff_1
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
buff_1 db 10 p(30h)
db 24h
CODE ENDS
END START
J. 如何將16進制轉化為圖片呢
你是想把一副圖片的數據嵌入你的源代碼中嗎?如果是,你可以編寫一個另外的程序,將bmp文件讀入,按c語言數組初始化的形式 輸出。比如下面的代碼
fp=fopen("aaa.bmp","br");
fseek(fp,0,SEEK_END)
int len=ftell(fp);
fseek(fp,0,SEEK_SET);
short *buff=(short *)malloc(len);
fread(buff,len,1,fp);
printf("unsigned short logo[]={\n");
for (i=0;i<len/2;i++)
printf("0x%04x,",buff[i]);
假如編譯好的程序名叫a.exe, 運行"a.exe > tmp.txt",將其輸出重定向到一個文件tmp.txt,然後拷貝粘貼到你的源代碼