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条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?