十六进制字符串jpg图片互转
十六制字符串jpg图片互转(格式:FFD8FFE000104A******)如:FFD8FFE000104A46494600010100000100010000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC00011080058004803012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00F7FA28ACBF10EB70787B42BAD52E3958532AB9FBEC780BF89A0076B5AFE9BE1FB2375A95CA429D141E59CFA01DEBCBB57F8DE03BC7A569C02F204970724FFC0474FCEBCB75DF126A5E28D61AE6EE4696673848D47CA83B2A8F4ABD65E10BAB840D3C8133D54734DB8C17BC5C61296C761A77C64D7448EF3C56D708173B0A6C23DC115B5A77C6E8E4942EA1A4948C9E5E193240FA11CFE75CB5AF85ADADEDCA6D62586093DEB1B54F0D35B8325B6463F84F4A855A0DD8D1D092573E8CD17C41A5F886D3ED1A6DDA4CA3EF28E193D88EA2B4EBE4CD175ED43C35ACC57B67214950F2A7A38EEAC3D2BEA0F0FEB50788743B5D52D81093A64A9EAAC3823F020D5B5630B1A745145200AF1DF8EDAD186CB4ED2236E642D3C833D870BFCDBF2AF62AF9D3E3679F3F8FA289C7C9F668D63E3B64E7F526AA3B8199E0FD26331FDA1973237F11EDF4AF44B28220A0605731A7E9EF15A476EB2F948AA0161D49ADFD3AD16D0EE5B992523AEF6CD724DA93BB67A14D5959235CC098FBB9ACCBF8E120AB0007BD6B971E56E2783E958375636524C64316641DC3722A2CBA9A4AFD0F3DF1669CB6D3F9E83E53DC57ABFC10D4C5CF866F2C5*********
/**
* 十六进制字节转字节数组
* Creates byte array representation of HEX string.<br>
* http://www.cnblogs.com/qgc88
* @param s
* string to parse
* @return
*/
public static byte[] fromHexString(String s) {
int length = s.length() / 2;
byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) {
bytes[i] = (byte) ((Character.digit(s.charAt(i * 2), 16) << 4) | Character
.digit(s.charAt((i * 2) + 1), 16));
}
return bytes;
}
/**
* Creates HEX String representation of supplied byte array.<br/>
* Each byte is represented by a double character element from 00 to ff
* 实现字节数组向十六进制的转换方法一 http://www.cnblogs.com/qgc88
* @param fieldData
* to be tringed
* @return
*/
public static String toHexString(byte[] fieldData) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fieldData.length; i++) {
int v = (fieldData[i] & 0xFF);
if (v <= 0xF) {
sb.append("0");
}
sb.append(Integer.toHexString(v));
}
return sb.toString();
}
//byte数组转图片 http://www.cnblogs.com/qgc88
public static void byte2image(byte[] data,String path){
if(data.length<3||path.equals("")) return;
try{
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));
imageOutput.write(data, 0, data.length);
imageOutput.close();
System.out.println("Make Picture success,Please find image in " + path);
} catch(Exception ex) {
System.out.println("Exception: " + ex);
ex.printStackTrace();
}
}
public static void main(String[] args) {
String str2="ffd8ffe000104a46494600010100000100010000f****ee3fdf4ff00d0857927f0cbf43fccd483";
byte[] t=fromHexString(str2);
byte2image(t, "d://1.jpg");//转成保存图片
/********************图片转十六进制******************************/
try
{
StringBuffer sb = new StringBuffer();
FileInputStream fis = new FileInputStream("d:/1.jpg");
BufferedInputStream bis = new BufferedInputStream(fis);
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] buff = new byte[1024];
int len = 0;
while ((len = fis.read(buff)) != -1)
{
bos.write(buff, 0, len);
}
// 得到图片的字节数组
byte[] result = bos.toByteArray();
System.out.println("++++" + toHexString(result));
// 字节数组转成十六进制
String str = toHexString(result);
//String str = byte2HexStr(result);
/* http://www.cnblogs.com/qgc88
* 将十六进制串保存到txt文件中
*/
PrintWriter pw = new PrintWriter(
new FileWriter("qgc88.txt"));
pw.println(str);
pw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
十六进制字符串jpg图片互转的更多相关文章
- C# base64编码的字符串与图片互转
protected string ImgToBase64String(string Imagefilename) { try { Bitmap bmp = new Bitmap(Imagefilena ...
- iOS 字符串和图片互转
for (UIImage *myImg in _imgArray) { NSData *imageData = UIImageJPEGRepresentation(myImg,0.5); NSStri ...
- Golang十六进制字符串和byte数组互转
Golang十六进制字符串和byte数组互转 需求 Golang十六进制字符串和byte数组互相转换,使用"encoding/hex"包 实现Demo package main i ...
- python 字节数组和十六进制字符串互转
. 字节数组 --> 十六进制字符串 >>> a = 'ab' >>> a.encode('hex') ' . 十六进制字符串 --> 字节数组 > ...
- UIColor与十六进制字符串互转
UIColor转十六进制字符串 方法一:经过测试发现部分颜色会转化为#fffff(五个f),转化残缺导致最后颜色无法还原,不推荐使用. // UIColor转#ffffff格式的字符串 + (NSSt ...
- delphi十六进制字符串hex转byte数组互相转换bmp图片
procedure Hex2Png(str: string; out png: TPngObject); var stream: TMemoryStream; begin if not Assigne ...
- 直接用<img> 的src属性显示base64转码后的字符串成图片
直接用<img> 的src属性显示base64转码后的字符串成图片 <img src="base64转码后的字符串" ></img> 下面的图片 ...
- Java中将0x开头的十六进制字符串转换成十进制整数
1.Integer.toString(int i) 由于input(输入数据)是以0x开头的字符串,并不是整型.因而在用 String s = Integer.toString(input); 时用会 ...
- Base64 字符串转图片 问题整理汇总
前言 最近碰到了一些base64字符串转图片的开发任务,开始觉得没啥难度,但随着开发的进展还是发现有些东西需要记录下. Base64 转二进制 这个在net有现有方法调用: Convert.FromB ...
随机推荐
- MySQL创建数据库,用户,赋予权限
CREATE DATABASE 'voyager'; CREATE DATABASE `voyager`; CREATE USER 'dog'@'localhost' IDENTIFIED BY '1 ...
- APP客户端图片上传PHP接口
1.客户端 file_get_contents($_FILES['img']['tmp_name']) //获取临时目录下的上传文件流,加密传给接口 2.接口处理端 $img = file_get ...
- 【android】安卓平台版本和API版本的对应关系
安卓平台版本和API版本对应关系
- CSS清除浮动8大方法
CSS清除浮动是每一位web前端工程师都要掌握的技术,也是让每一位刚入门的前端工程师感到头疼的问题, 下面就来讲一下CSS清除浮动的原理和各种解决方法,大家可以根据实际情况选择最佳的解决方案. 在用D ...
- python爬虫基础09-selenium大全3/8-Remote Webdriver
Selenium笔记(3)Remote Webdriver 本文集链接:https://www.jianshu.com/nb/25338984 简介 selenium.webdriver.remote ...
- 【转】MySQL innodb_autoinc_lock_mode 详解 ,并发插入时主键冲突的解决方案
本文转载于 http://www.cnblogs.com/JiangLe/p/6362770.html innodb_autoinc_lock_mode这个参数控制着在向有auto_increment ...
- InnoDB Redo Flush及脏页刷新机制深入分析
概要: 我们知道InnoDB采用Write Ahead Log策略来防止宕机数据丢失,即事务提交时,先写重做日志,再修改内存数据页,这样就产生了脏页.既然有重做日志保证数据持久性,查询时也可以直接从缓 ...
- 2015四川省赛 D Vertex Cover 搜索
题意: 给出一个\(n\)个点\(m\)条边的无向图,现在要给若干个点染色,使得每条边都至少邻接一个被染色的顶点.问至少要给多少各点染色才能满足条件. 分析: 注意到题目中有一个很特殊的条件: 对于图 ...
- LoadRunner11使用方法以及注意点收集
一:安装loadrunner http://jingyan.baidu.com/article/f7ff0bfc1cc82c2e26bb13b7.html http://www.cnblogs.com ...
- Java-一个数组中的元素复制到另一个数组
public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length).其中五个参数分别表示为: ...