croping图像并保存到特定的文件夹在SD卡(机器人)? [英] croping image and save to specific folder in sdcard (android)?

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

问题描述

我形象一直crop.i想要的图像保存到文件夹(SD卡)...我已经做了裁剪图像,并显示到ImageView的,但我的问题是,我不知道如何保存图像裁切到SD卡??

这是我的code的成功裁剪图像。

 捆绑额外= data.getExtras();   如果(临时演员!= NULL){
        位图照片= extras.getParcelable(数据);
        mImageView.setImageBitmap(照片);
   }

也许有人对你能有所帮助,在那里我可以添加code保存裁切图像?
感谢..


解决方案

试用这种方式:


 捆绑m_extras = data.getExtras();
 //获取裁剪位图
 位图m_thePic = m_extras.getParcelable(数据);
 。字符串m_path = Environment.getExternalStorageDirectory()的toString();
文件m_imgDirectory =新的文件(m_path +/图片/);
如果m_imgDirectory.mkdir()(m_imgDirectory.exists()!);
OutputStream的m_fOut = NULL;
文件m_file =新的文件(m_path);
m_file.delete();
字符串m_fileid = System.currentTimeMillis的()+;
m_file =新的文件(m_path,/图片/+ m_fileid +巴纽);
尝试
{
    如果m_file.createNewFile()(m_file.exists()!);
    m_fOut =新的FileOutputStream(m_file);
    位图m_bitmap = m_thePic.copy(Bitmap.Config.ARGB_8888,真);
    m_bitmap.com preSS(Bitmap.Com pressFormat.PNG,100,m_fOut);
    m_fOut.flush();
    m_fOut.close();
    MediaStore.Images.Media.insertImage(getContentResolver(),
            m_file.getAbsolutePath(),m_file.getName(),m_file.getName());
}
赶上(例外p_e)
{
}


添加下面的权限清单文件。

 <使用许可权的android:NAME =android.permission.CAMERA/>
    <使用特征的android:NAME =android.hardware.camera/>
    <使用特征的android:NAME =android.hardware.camera.autofocus/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权的android:NAME =android.permission.READ_EXTERNAL_STORAG​​E/>

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);
   }

perhaps anyone of you can help, where I can add the code to save an image that have been cropped?? thanks..

解决方案

Try out this way:

 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"/>

这篇关于croping图像并保存到特定的文件夹在SD卡(机器人)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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