完整代码请看我博客,解决了我会悬赏
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 3:
if (Bimp.tempSelectBitmap.size() == a) {
a = 0;
releaseMessage();
dialog.dismiss();
return;
}
String path = Bimp.tempSelectBitmap.get(a).getImagePath();
if (path == null) {
Bitmap bm = Bimp.tempSelectBitmap.get(a).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
if (bm != null) {
final File tempFile = new File(getCacheDir(),
"temp.png");
try {
byte[] dataBytes = stream.toByteArray();
FileOutputStream fileOut = new FileOutputStream(
tempFile);
fileOut.write(dataBytes);
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (tempFile.exists()) {
falg1 = 0;
final String pic_path = tempFile.getPath();
String targetPath = getTempDirectoryPath()
+ "compressPic.jpg";
// 调用压缩图片的方法,返回压缩后的图片path
final String compressImage = PicUtils
.compressImage(pic_path, targetPath, 50);
final File compressedPic = new File(compressImage);
if (compressedPic.exists()) {
uploadPics(compressedPic);
} else {// 直接上传
uploadPics(tempFile);
}
++a;
}
}
}
if (path != null) {
falg1 = 1;
String targetPath = getTempDirectoryPath()
+ "compressPic.jpg";
// 调用压缩图片的方法,返回压缩后的图片path
final String compressImage = PicUtils.compressImage(path,
targetPath, 50);
final File compressedPic = new File(compressImage);
if (compressedPic.exists()) {
uploadPics(compressedPic);
} else {// 直接上传
uploadPics(new File(path));
}
}
++a;
break;
}
}
};