裁剪图像并保存到sdcard(Android)中的特定文件夹? [英] cropping image and save to specific folder in sdcard (Android)?

查看:161
本文介绍了裁剪图像并保存到sdcard(Android)中的特定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图像被裁剪了。我想将该图像保存到文件夹(sdcard)...我已经完成了裁剪图像并显示到imageview,但是我的问题是,我不知道如何将图像裁剪保存到sdcard?

I've image has been crop. I want that image save to folder (sdcard)...I've already done crop image and show to imageview, but my problem is, I don't know how saving image crop to sdcard ?

这是我的代码已成功裁剪图像。.

here is my code has success to crop an image..

Bundle extras = data.getExtras();

if (extras != null) {               
    Bitmap photo = extras.getParcelable("data");
    mImageView.setImageBitmap(photo);
}

在这里我可以添加代码以保存已裁剪的图像吗? / p>

where I can add the code to save an image that have been cropped?

推荐答案

尝试这种方式:


 Bundle m_extras = data.getExtras();
 // get the cropped bitmap
 Bitmap m_thePic = m_extras.getParcelable("data");
 String m_path = Environment.getExternalStorageDirectory().toString();
File m_imgDirectory = new File(m_path + "/Images/");
if (!m_imgDirectory.exists()) m_imgDirectory.mkdir();
OutputStream m_fOut = null;
File m_file = new File(m_path);
m_file.delete();
String m_fileid = System.currentTimeMillis() + "";
m_file = new File(m_path, "/Images/" + m_fileid + ".png");  
try
{
    if (!m_file.exists()) m_file.createNewFile();
    m_fOut = new FileOutputStream(m_file);      
    Bitmap m_bitmap = m_thePic.copy(Bitmap.Config.ARGB_8888, true);
    m_bitmap.compress(Bitmap.CompressFormat.PNG, 100, m_fOut);
    m_fOut.flush();
    m_fOut.close();
    MediaStore.Images.Media.insertImage(getContentResolver(),
            m_file.getAbsolutePath(), m_file.getName(), m_file.getName());
}
catch (Exception p_e)
{
}


在清单文件中添加以下权限。

Add below permission in manifest file.

  <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

这篇关于裁剪图像并保存到sdcard(Android)中的特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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