安卓的一些图片操作小计

    /**
    * 将bitmap保存到本地
     */
     public static File saveImg(Bitmap b, String outPath, int q) {
        File mediaFile = new File(outPath);
        try {
            if (mediaFile.exists()) {
                mediaFile.delete();
            }
            if (!mediaFile.getParentFile().exists()) {
                mediaFile.getParentFile().mkdirs();
            }
            mediaFile.createNewFile();
            FileOutputStream fos = new FileOutputStream(mediaFile);
            b.compress(Bitmap.CompressFormat.JPEG, q, fos);
            fos.flush();
            fos.close();
            b.recycle();
            b = null;
            System.gc();
            return mediaFile;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
    * 将bitmap转化成二进制流进行传递
     */
//传送方

ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);//压缩 
byte[] datas = baos.toByteArray();
Intent intent = getIntent();
intent.putExtra("bitmap", datas);

//接受方
byte[] b = intent.getByteArrayExtra("bitmap");
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);

你可能感兴趣的:(android)