要保存在SD卡图像 [英] To save the image in sdcard

查看:140
本文介绍了要保存在SD卡图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了$ C $下编辑图片,现在我要保存编辑后的图像中的SD卡

 图像=(ImageView的)findViewById(R.id.image);
        意向意图= getIntent();
        文件sdCardDirectory = Environment.getExternalStorageDirectory();
        相片=(位图)intent.getParcelableExtra(photoo);
        image.setImageBitmap(照片);
 

解决方案

试试这个,

 无效saveImage(){

    。串根= Environment.getExternalStorageDirectory()的toString();
    文件MYDIR =新的文件(根+/ saved_images);

    字符串FNAME =image.jpg的;
    档案文件=新的文件(MYDIR,FNAME);
    如果(file.exists())file.delete();
    尝试 {
           FileOutputStream中出=新的FileOutputStream(文件);
           myBitmap.com preSS(Bitmap.Com pressFormat.JPEG,90,出);
           了out.flush();
           out.close();

    }赶上(例外五){
           e.printStackTrace();
    }
}
 

I have Written the code for Editing the Image now I want to save that edited image in the sdcard

image=(ImageView)findViewById(R.id.image);
        Intent intent = getIntent();
        File sdCardDirectory = Environment.getExternalStorageDirectory();
        photo = (Bitmap) intent.getParcelableExtra("photoo");
        image.setImageBitmap(photo);

解决方案

Try this,

 void saveImage() {

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");

    String fname = "Image.jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           myBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
    }
}

这篇关于要保存在SD卡图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆