如果我直接上传原图是没有任何问题的,但是我要的是将图片进行压缩后再上传,php服务器再根据接收的图片和压缩比例,将接收的图片按比例放大为原图的大小。这些都做到了,可问题是图片失真
下面贴出我的部分java客户端代码和php服务器端代码,大家帮我看看问题出在哪里:
public class myThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
String r = null;
upload_fail = new ArrayList<HashMap<String, String>>();
if (!catid.equals(null)) {
for (HashMap<String, String> map : path_list) {
String path = map.get("img_path");
Bitmap bit = BitmapFactory.decodeFile(path);
float pc = (float) 100 / (float) bit.getWidth();//压缩比例
Bitmap bit2 = resize_img(bit, pc);//压缩bitmap
String filename = path.substring(path.lastIndexOf("/") + 1);
File file = saveMyBitmap(filename, bit2);
//File file = new File(path);//若上传原图则用这一行代码代替上面5行即可
upload_res = UploadUtil.uploadFile(file, pc, actionUrl, catid, s_sessid, s_psnId);//上传(返回一个HashMap)
String result = upload_res.get("ans").toString();
if (!result.equals("success")) {
//失败
HashMap<String, String> fail_map = new HashMap<String, String>();
fail_map.put("name", file.getName());
fail_map.put("path", path);
upload_fail.add(fail_map);
} else {
//成功
file.delete();
bit2.recycle();
bit2 = null;
System.gc();
upload_success.add(map.get("thrum_path"));
}
}
s_psnId = upload_res.get("sess_psnId").toString();
s_sessid = upload_res.get("sessionId").toString();
if (upload_fail.size() == 0) {
//全部成功
r = "success";
}else {
if (upload_success.size() == 0) {
//全部失败
r = upload_res.get("ans").toString();
} else {
//部分失败
r = "对不起,图片 [ ";
for (HashMap<String, String> map : upload_fail) {
r += map.get("name") + " ";
}
r += "] 上传失败!";
}
}
} else {
r = "请选择相册";
}
Message msg = myHand.obtainMessage();
Bundle b = new Bundle();
b.putString("res", r);
msg.setData(b);