图片转码问题,help!
本地有张图片A.jpg转UTF-8 存入A1.jpg
A1.jpg 进行转码ASCII 存入A2.jpg ,但是显示不出图片
//测试2
public void test2(){
InputStream fis = null;
FileOutputStream fos = null;
try {
//读取某个文件转换成字符串
String str = FileUtil.readFileByBete("c:/MMpic/A.jpg", "UTF-8");
System.out.println(str);
byte[] b = new byte[1024 * 5];
fis = new ByteArrayInputStream(str.getBytes());
fos = new FileOutputStream("c:/MMpic/A1.jpg");
while(fis.read(b)!=-1){
fos.write(b);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try{
if(fis!=null) fis.close();
if(fos!=null) fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
//读取某个文件转换成字符串
public static String readFileByBete(String filePath,String charset){
FileInputStream br = null;
ByteArrayOutputStream outbyte = null;
try {
br = new FileInputStream(new File(filePath));
outbyte = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length=0;
while((length=br.read(buffer))!=-1){
outbyte.write(buffer, 0, length);
}
}catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e2){
e2.printStackTrace();
}finally{
try{
br.close();
}catch(IOException e3){
e3.printStackTrace();
}
}
try {
return new String(outbyte.toByteArray(),charset);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
哪位大神帮俺看看 --------------------编程问答-------------------- 图片信息本来就是二进制的,LZ这个转码有什么特殊意义吗?
你把图片的二进制信息转成字符串,然后再把字符串转成别的编码的二进制信息保存,你觉得这样的图片信息还正确吗?
fis = new ByteArrayInputStream(str.getBytes("UTF-8"));//按什么编码转成字符串的,再按什么编码转回去,否则图片信息肯定不一样了,也就是图片就不正确了,还怎么显示
--------------------编程问答-------------------- 图片怎么转utf8啊 --------------------编程问答-------------------- 我说下 详情情况吧。
服务器下发一个 图片地址 让客户端(sysbian) 访问这个地址 ,客户端返回的是utf-8 的字符串,我需要对这个字符串操作 转成图片。客户端程序不可以更改了。
--------------------编程问答-------------------- 有大神,遇到这种情况的,指点一二,不慎感激,在线等 --------------------编程问答-------------------- 楼主应该是要画图吧 ,可以参考下很多的验证码是怎么写的,这方面我也不是很了解 --------------------编程问答-------------------- 差不多,我现在就是得到utf-8 的字符串 转编码 jpg文件显示不出来。
补充:Java , Java EE