例如图片原始数据为:(UTF-8)
UExUReDCv01SMSuOzV4aGEpKS8ulosKcmtKuqc/H1NKyrQgJBzQzKeXIxffz+c2sqsSindy+umGk1NptkLOzj8S+zSt2s4+w1zFIZ4QaIG5IQL6ZldO1sI+Q
b8+wqo50c21xSNu6ta12a8ejobCuupNTJ46EismjnehZec6qpnNrbyGW1MqopoNRS86nJ9SMeCkqIc6up7uFcDCq49BRIpJmW+C+vMqoonp/Wc6oorSOhTxD..................................................
9 个解决方案
#1
用。String.getBytes
而且看到的应该不是UTF8编码出来的东西,应该是Base64的。
你可以用Base64Encode和Base64Decode来处理。
至于Base64是不是处理的UTF8字节流就不知道了。
而且看到的应该不是UTF8编码出来的东西,应该是Base64的。
你可以用Base64Encode和Base64Decode来处理。
至于Base64是不是处理的UTF8字节流就不知道了。
#2
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import sun.misc.BASE64Decoder;
public class Base64ToImage {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String imgStr ="/9j/4AAQSkZJRgABAgAAAQABAAD/4QDmRXhpZgAASUkqAAgAAAAFABIBAwABAAAAAQAAADEBAgAc" +
"AAAASgAAADIBAgAUAAAAZgAAABMCAwABAAAAAQAAAGmHBAABAAAAegAAAAAAAABBQ0QgU3lzdGVt" +
"cyBEaWdpdGFsIEltYWdpbmcAMjAwNTowMTowOSAxMzo1MTo1OQAFAACQBwAEAAAAMDIxMJCSAgAE" +
"AAAAMjE4AAKgBAABAAAAKAAAAAOgBAABAAAAKAAAAAWgBAABAAAAvAAAAAAAAAACAAEAAgAEAAAA" +
"Ujk4AAIABwAEAAAAMDEwMAAAAACEhISE/8AAEQgAKAAoAwEiAAIRAQMRAf/bAIQAAQEBAQEBAQEB" +
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB" +
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA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W0ZjSJqaVPyEhJtvqKZyO5JkEtN5fwtDacLV0b/eo9iyf8s3PrpjpKPcD/NUT8kde/VVzpFuX6jV" +
"1vJerjkrkp3nscfmjbWdgYSe+0hqHVCyRjTpmTe7UUPeaEqOgvn1+0JIiP45AeW5K/HHcvztCCBj" +
"taQcwnSdyTJGwikZgEVSv096SOCCpMxM+9Y/8yUn4tVH/KHuf8pLlu0+/wBCnAtKRTJkVmLr9FwC" +
"UWY1CyjMgIdarATDtOSkuXllsM5qPHj4xiM9MUw0SjLpD0F+Fz58/r3sXzeM/wCb0E+z/az377/c" +
"nqsetZUvGHBZOdlqLcxj3mc1E7DRkVP2vNGWFc7j7A1aWaaOT5uQpK/9z8UitIpWueWp2nTM6+xb" +
"+50ABDq6CqigHnaqJKLtlouoqIhiSMAB+o6RN73tFYsUhCexLf/Z";
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] imgBytes = decoder.decodeBuffer(imgStr);
File decFile = new File("C:\\cat.jpg");
FileOutputStream ops = new FileOutputStream(decFile);
ops.write(imgBytes, 0, imgBytes.length);
ops.flush();
ops.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
import java.io.FileOutputStream;
import java.io.IOException;
import sun.misc.BASE64Decoder;
public class Base64ToImage {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String imgStr ="/9j/4AAQSkZJRgABAgAAAQABAAD/4QDmRXhpZgAASUkqAAgAAAAFABIBAwABAAAAAQAAADEBAgAc" +
"AAAASgAAADIBAgAUAAAAZgAAABMCAwABAAAAAQAAAGmHBAABAAAAegAAAAAAAABBQ0QgU3lzdGVt" +
"cyBEaWdpdGFsIEltYWdpbmcAMjAwNTowMTowOSAxMzo1MTo1OQAFAACQBwAEAAAAMDIxMJCSAgAE" +
"AAAAMjE4AAKgBAABAAAAKAAAAAOgBAABAAAAKAAAAAWgBAABAAAAvAAAAAAAAAACAAEAAgAEAAAA" +
"Ujk4AAIABwAEAAAAMDEwMAAAAACEhISE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iESS6Sb" +
"X9mgDPpUTk/KVcHRx7Dtb8tYL9kmqWSXuWhC1XuAweUvL3RYJhNm5KdrjkjHzLgrZ5U/LV6qQkyQ" +
"C0pxtJklIV23AnnjN4bVj156iHMJaUnGVIaxhFFzHdF1Jxv13Kt6z4G7V0lT5kUcuTmFVumiNzaT" +
"W0ZjSJqaVPyEhJtvqKZyO5JkEtN5fwtDacLV0b/eo9iyf8s3PrpjpKPcD/NUT8kde/VVzpFuX6jV" +
"1vJerjkrkp3nscfmjbWdgYSe+0hqHVCyRjTpmTe7UUPeaEqOgvn1+0JIiP45AeW5K/HHcvztCCBj" +
"taQcwnSdyTJGwikZgEVSv096SOCCpMxM+9Y/8yUn4tVH/KHuf8pLlu0+/wBCnAtKRTJkVmLr9FwC" +
"UWY1CyjMgIdarATDtOSkuXllsM5qPHj4xiM9MUw0SjLpD0F+Fz58/r3sXzeM/wCb0E+z/az377/c" +
"nqsetZUvGHBZOdlqLcxj3mc1E7DRkVP2vNGWFc7j7A1aWaaOT5uQpK/9z8UitIpWueWp2nTM6+xb" +
"+50ABDq6CqigHnaqJKLtlouoqIhiSMAB+o6RN73tFYsUhCexLf/Z";
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] imgBytes = decoder.decodeBuffer(imgStr);
File decFile = new File("C:\\cat.jpg");
FileOutputStream ops = new FileOutputStream(decFile);
ops.write(imgBytes, 0, imgBytes.length);
ops.flush();
ops.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
#3
不错哦。学习了。
我还没用过。用XML保存图片数据的哦。
我还没用过。用XML保存图片数据的哦。
#4
#5
up
#6
如果这些数据被传到J2ME客户端中呢?是要重新写一个BASE64解释类?
#7
已知XML里面保存图片的原始数据,求还原图片的方法~
LZ贴出来的东西这是XML保存图形数据吗~~我这里倒有个例子
<?xml version="1.0" encoding="gb2312"?>
<vg version="460" gridsize="2" range="100,850,420,990" bordericons="3" borderstyle="1" scrollbars="3" windowstate="0" backcolor="$FFFFFF" enzoom="0" picname="''" viewheight="140" viewwidth="320" winrefresh="1" wintype="2">
<page name="page" bounds="0,0,793.700787402,1122.141732283" visible="false" margin="100,100,100,100" paperwidth="2100" paperheight="2969"/>
<sheet name="sheet1" bounds="101,851,415,956" caption="'2#电容器VQC自动复归闭锁信息号'">
<rect name="rect2" bounds="101,851,413,956" origin="506,1020.621002197" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$800000" backcolor="$A4A0A0" pattern="1"/>
<line name="line15" origin="225,927" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$FFFFFF">
<points>
103,879.303030304,6
413.025316456,879.303030304,2
</points>
贴一部分吧~~这是形容一个图形的,包括他的坐标,动作,颜色等属性
在程序里面用DOM4J解析出来,再PAINT出来就可以了
LZ贴出来的东西这是XML保存图形数据吗~~我这里倒有个例子
<?xml version="1.0" encoding="gb2312"?>
<vg version="460" gridsize="2" range="100,850,420,990" bordericons="3" borderstyle="1" scrollbars="3" windowstate="0" backcolor="$FFFFFF" enzoom="0" picname="''" viewheight="140" viewwidth="320" winrefresh="1" wintype="2">
<page name="page" bounds="0,0,793.700787402,1122.141732283" visible="false" margin="100,100,100,100" paperwidth="2100" paperheight="2969"/>
<sheet name="sheet1" bounds="101,851,415,956" caption="'2#电容器VQC自动复归闭锁信息号'">
<rect name="rect2" bounds="101,851,413,956" origin="506,1020.621002197" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$800000" backcolor="$A4A0A0" pattern="1"/>
<line name="line15" origin="225,927" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$FFFFFF">
<points>
103,879.303030304,6
413.025316456,879.303030304,2
</points>
贴一部分吧~~这是形容一个图形的,包括他的坐标,动作,颜色等属性
在程序里面用DOM4J解析出来,再PAINT出来就可以了
#8
用BASE64编码解码是比较好的做法,在JDK或者网上也比较容易找到现成的算法。
#9
up 学习了
#10
是说J2ME里,不是J2SE,
#1
用。String.getBytes
而且看到的应该不是UTF8编码出来的东西,应该是Base64的。
你可以用Base64Encode和Base64Decode来处理。
至于Base64是不是处理的UTF8字节流就不知道了。
而且看到的应该不是UTF8编码出来的东西,应该是Base64的。
你可以用Base64Encode和Base64Decode来处理。
至于Base64是不是处理的UTF8字节流就不知道了。
#2
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import sun.misc.BASE64Decoder;
public class Base64ToImage {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String imgStr ="/9j/4AAQSkZJRgABAgAAAQABAAD/4QDmRXhpZgAASUkqAAgAAAAFABIBAwABAAAAAQAAADEBAgAc" +
"AAAASgAAADIBAgAUAAAAZgAAABMCAwABAAAAAQAAAGmHBAABAAAAegAAAAAAAABBQ0QgU3lzdGVt" +
"cyBEaWdpdGFsIEltYWdpbmcAMjAwNTowMTowOSAxMzo1MTo1OQAFAACQBwAEAAAAMDIxMJCSAgAE" +
"AAAAMjE4AAKgBAABAAAAKAAAAAOgBAABAAAAKAAAAAWgBAABAAAAvAAAAAAAAAACAAEAAgAEAAAA" +
"Ujk4AAIABwAEAAAAMDEwMAAAAACEhISE/8AAEQgAKAAoAwEiAAIRAQMRAf/bAIQAAQEBAQEBAQEB" +
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB" +
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB" +
"AQEBAQEB/8QAjgAAAgMBAQAAAAAAAAAAAAAACAkGBwoFCxAAAQQCAQICAwkRAAAAAAAABAIDBQYB" +
"BwgACRIVERM1FBYZVnaUlbPTChcYIjE4VFdYc3R3k7G0w9UBAAIDAQAAAAAAAAAAAAAAAAcIAgYJ" +
"BREAAgMBAAIDAAICAwAAAAAAAwQBAgUGBxIRExQAFQgiIzEz/9oADAMBAAIRAxEAPwBtml+PXH7i" +
"JeebnMW+Vy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fz58/r3sXzeM/wCb0E+z/az377/c" +
"nqsetZUvGHBZOdlqLcxj3mc1E7DRkVP2vNGWFc7j7A1aWaaOT5uQpK/9z8UitIpWueWp2nTM6+xb" +
"+50ABDq6CqigHnaqJKLtlouoqIhiSMAB+o6RN73tFYsUhCexLf/Z";
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] imgBytes = decoder.decodeBuffer(imgStr);
File decFile = new File("C:\\cat.jpg");
FileOutputStream ops = new FileOutputStream(decFile);
ops.write(imgBytes, 0, imgBytes.length);
ops.flush();
ops.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
import java.io.FileOutputStream;
import java.io.IOException;
import sun.misc.BASE64Decoder;
public class Base64ToImage {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String imgStr ="/9j/4AAQSkZJRgABAgAAAQABAAD/4QDmRXhpZgAASUkqAAgAAAAFABIBAwABAAAAAQAAADEBAgAc" +
"AAAASgAAADIBAgAUAAAAZgAAABMCAwABAAAAAQAAAGmHBAABAAAAegAAAAAAAABBQ0QgU3lzdGVt" +
"cyBEaWdpdGFsIEltYWdpbmcAMjAwNTowMTowOSAxMzo1MTo1OQAFAACQBwAEAAAAMDIxMJCSAgAE" +
"AAAAMjE4AAKgBAABAAAAKAAAAAOgBAABAAAAKAAAAAWgBAABAAAAvAAAAAAAAAACAAEAAgAEAAAA" +
"Ujk4AAIABwAEAAAAMDEwMAAAAACEhISE/8AAEQgAKAAoAwEiAAIRAQMRAf/bAIQAAQEBAQEBAQEB" +
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB" +
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB" +
"AQEBAQEB/8QAjgAAAgMBAQAAAAAAAAAAAAAACAkGBwoFCxAAAQQCAQICAwkRAAAAAAAABAIDB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RjTpmTe7UUPeaEqOgvn1+0JIiP45AeW5K/HHcvztCCBj" +
"taQcwnSdyTJGwikZgEVSv096SOCCpMxM+9Y/8yUn4tVH/KHuf8pLlu0+/wBCnAtKRTJkVmLr9FwC" +
"UWY1CyjMgIdarATDtOSkuXllsM5qPHj4xiM9MUw0SjLpD0F+Fz58/r3sXzeM/wCb0E+z/az377/c" +
"nqsetZUvGHBZOdlqLcxj3mc1E7DRkVP2vNGWFc7j7A1aWaaOT5uQpK/9z8UitIpWueWp2nTM6+xb" +
"+50ABDq6CqigHnaqJKLtlouoqIhiSMAB+o6RN73tFYsUhCexLf/Z";
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] imgBytes = decoder.decodeBuffer(imgStr);
File decFile = new File("C:\\cat.jpg");
FileOutputStream ops = new FileOutputStream(decFile);
ops.write(imgBytes, 0, imgBytes.length);
ops.flush();
ops.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
#3
不错哦。学习了。
我还没用过。用XML保存图片数据的哦。
我还没用过。用XML保存图片数据的哦。
#4
#5
up
#6
如果这些数据被传到J2ME客户端中呢?是要重新写一个BASE64解释类?
#7
已知XML里面保存图片的原始数据,求还原图片的方法~
LZ贴出来的东西这是XML保存图形数据吗~~我这里倒有个例子
<?xml version="1.0" encoding="gb2312"?>
<vg version="460" gridsize="2" range="100,850,420,990" bordericons="3" borderstyle="1" scrollbars="3" windowstate="0" backcolor="$FFFFFF" enzoom="0" picname="''" viewheight="140" viewwidth="320" winrefresh="1" wintype="2">
<page name="page" bounds="0,0,793.700787402,1122.141732283" visible="false" margin="100,100,100,100" paperwidth="2100" paperheight="2969"/>
<sheet name="sheet1" bounds="101,851,415,956" caption="'2#电容器VQC自动复归闭锁信息号'">
<rect name="rect2" bounds="101,851,413,956" origin="506,1020.621002197" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$800000" backcolor="$A4A0A0" pattern="1"/>
<line name="line15" origin="225,927" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$FFFFFF">
<points>
103,879.303030304,6
413.025316456,879.303030304,2
</points>
贴一部分吧~~这是形容一个图形的,包括他的坐标,动作,颜色等属性
在程序里面用DOM4J解析出来,再PAINT出来就可以了
LZ贴出来的东西这是XML保存图形数据吗~~我这里倒有个例子
<?xml version="1.0" encoding="gb2312"?>
<vg version="460" gridsize="2" range="100,850,420,990" bordericons="3" borderstyle="1" scrollbars="3" windowstate="0" backcolor="$FFFFFF" enzoom="0" picname="''" viewheight="140" viewwidth="320" winrefresh="1" wintype="2">
<page name="page" bounds="0,0,793.700787402,1122.141732283" visible="false" margin="100,100,100,100" paperwidth="2100" paperheight="2969"/>
<sheet name="sheet1" bounds="101,851,415,956" caption="'2#电容器VQC自动复归闭锁信息号'">
<rect name="rect2" bounds="101,851,413,956" origin="506,1020.621002197" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$800000" backcolor="$A4A0A0" pattern="1"/>
<line name="line15" origin="225,927" showHint="false" fillfq="0" linefq="0" picname="''" linewidth="2" linecolor="$FFFFFF">
<points>
103,879.303030304,6
413.025316456,879.303030304,2
</points>
贴一部分吧~~这是形容一个图形的,包括他的坐标,动作,颜色等属性
在程序里面用DOM4J解析出来,再PAINT出来就可以了
#8
用BASE64编码解码是比较好的做法,在JDK或者网上也比较容易找到现成的算法。
#9
up 学习了
#10
是说J2ME里,不是J2SE,