lap602651857 2018-05-30 07:00 采纳率: 0%
浏览 702
已采纳

Android 多次拍照上传内存溢出 上个被删掉了 血亏一波

完整代码请看我博客,解决了我会悬赏
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;

        }
    }
};
  • 写回答

3条回答 默认 最新

  • bilionera 2018-05-30 09:22
    关注

    你拿到的图片有经过压缩吗,使用过bitmap后有释放吗,你这代码还有很长的路要走啊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。