android打开保存图片格式,Android内存中位图/图像的保存与读取

使用下面的代码将图像保存到内部目录。private String saveToInternalStorage(Bitmap bitmapImage){

ContextWrapper cw = new ContextWrapper(getApplicationContext());

// path to /data/data/yourapp/app_data/imageDir

File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);

// Create imageDir

File mypath=new File(directory,"profile.jpg");

FileOutputStream fos = null;

try {

fos = new FileOutputStream(mypath);

// Use the compress method on the BitMap object to write image to the OutputStream

bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

fos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return directory.getAbsolutePath();

}

说明:

1.目录将使用给定的名称创建。Javadocs是用来告诉它将在哪里创建目录的。

2.您必须给出要保存它的图像名称。

若要从内部内存读取文件,请执行以下操作。使用以下代码private void loadImageFromStorage(String path){

try {

File f=new File(path, "profile.jpg");

Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));

ImageView img=(ImageView)findViewById(R.id.imgPicker);

img.setImageBitmap(b);

}

catch (FileNotFoundException e)

{

e.printStackTrace();

}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值