| | |
| | | String fileName = mediafile.getGuid()+".jpg"; |
| | | File outputFile = new File(Environment.getExternalStorageDirectory(),path+fileName); |
| | | outputFile.getParentFile().mkdirs(); |
| | | |
| | | BitmapFactory.Options opts = new BitmapFactory.Options(); |
| | | //将图片的长宽缩小为1/2 |
| | | opts.inSampleSize = 2; |
| | |
| | | if (bm!=null){ |
| | | bmSmall= Bitmap.createScaledBitmap(bm,width,height,true); |
| | | try { |
| | | // 当图片大于1MB时,才会进行压缩处理 |
| | | if (file.length() > 1024L * 1024) { |
| | | bmSmall.compress(Bitmap.CompressFormat.JPEG, 80, new FileOutputStream(outputFile.getAbsolutePath())); |
| | | } else { |
| | | bmSmall.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(outputFile.getAbsolutePath())); |
| | | } |
| | | Log.i("compress success",outputFile.getAbsolutePath()); |
| | | outputFIleList.add(outputFile); |
| | | bm.recycle(); |
| | | bm=null; |
| | | bmSmall.recycle(); |
| | | bmSmall =null; |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | Log.i("compress failure",outputFile.getAbsolutePath()); |