一个demo,实现调用系统相机拍照,将其显示在屏幕上,并且存到sd卡。  -IMDN开发者社群-imdn.cn">     一个demo,实现调用系统相机拍照,将其显示在屏幕上,并且存到sd卡。   - IMDN开发者社群-imdn.cn">
登录
首页 » Java » android 实现调用系统相机拍照,并且存到sd卡 实例 附完整源码

android 实现调用系统相机拍照,并且存到sd卡 实例 附完整源码

于 2013-06-13 发布
0 132
下载积分: 1 下载次数: 0

代码说明:

一个demo,实现调用系统相机拍照,将其显示在屏幕上,并且存到sd卡。     Android中实现拍照有两种方法,一种是调用系统自带的相机,然后使用其返回的照片数据。 还有一种是自己用Camera类和其他相关类实现相机功能,这种方法定制度比较高,洗染也比较复杂,一般平常的应用只需使用第一种即可。 用Intent启动相机的代码:Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivityForResult(intent, 1); 拍完照后就可以在onActivityResult(int requestCode, int resultCode, Intent data)中获取到Bitmap对象了。Bitmap bitmap = (Bitmap) data.getExtras().get("data"); 要将图像存储到sd卡之前最好先检查一下sd卡是否可用     String sdStatus = Environment.getExternalStorageState();            if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用                Log.v("TestFile",                        "SD card is not avaiable/writeable right now.");                return;            }   以下代码可以实现将图像文件存到“sdcard/myImage/”文件夹下,名称为“111.jpg”            File file = new File("/sdcard/myImage/");            file.mkdirs();// 创建文件夹            String fileName = "/sdcard/myImage/111.jpg";             try {                b = new FileOutputStream(fileName);                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件            } catch (FileNotFoundException e) {                e.printStackTrace();            } finally {                try {                    b.flush();                    b.close();                } catch (IOException e) {                    e.printStackTrace();                }            } 另外要注意的是读写sd卡文件必须首先要在Mainifest.xml文件中配置权限:           一个demo,实现调用系统相机拍照,将其显示在屏幕上,并且存到sd卡。    

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • android短信功能
    android短信功能 核心代码:package cn.edu.siso;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.InputSource;import org.xml.sax.XMLReader;import android.app.ListActivity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.view.Window;import android.widget.Button;import android.widget.ListView;import android.widget.SimpleAdapter;import cn.edu.ContentProvide.Diary.DiaryColumns;import cn.edu.Info.MyInfo;import cn.edu.MyContentHandler.MyContentHandler;import cn.edu.siso.WareHouselistview.SMSBsharpturn;import cn.edu.siso.WareHouselistview.SMSFriendTab;import cn.edu.siso.WareHouselistview.SMSHavefanTab;import cn.edu.siso.WareHouselistview.SMSLoverTab;import cn.edu.siso.WareHouselistview.SMSSchooljoke;import cn.edu.siso.WareHouselistview.SMSapologize;import cn.edu.siso.WareHouselistview.SMShumorjokes;import cn.edu.siso.WareHouselistview.SMSlovewords;import cn.edu.siso.WareHouselistview.SMSmylove;import cn.edu.siso.WareHouselistview.SMSplayful;public class WareHouseActivity extends ListActivity { /** Called when the activity is first created. */ private List mp3Infos=null; private ListView listview; private Button back,updata; public static final String[] PROJECTION = new String[] { DiaryColumns._ID,DiaryColumns.TITLE, DiaryColumns.CREATED }; private Touch touch=new Touch(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.warehouse); listview=(ListView) findViewById(android.R.id.list); listview.setScrollingCacheEnabled(false); ShowListView(); back=(Button) findViewById(R.id.back); updata=(Button) findViewById(R.id.updata); back.setOnClickListener(new backlistener()); updata.setOnClickListener(new updatalistener()); back.setOnTouchListener(touch); updata.setOnTouchListener(touch); } private SimpleAdapter budildSimpleAdapter(List mp3Infos){ List list=new ArrayList(); for (Iterator iterator = mp3Infos.iterator(); iterator.hasNext();) { MyInfo mp3Info = (MyInfo) iterator.next(); HashMap map=new HashMap(); map.put("name", mp3Info.getName()); map.put("listimageview", R.drawable.image); list.add(map); } SimpleAdapter listadapter=new SimpleAdapter(this, list, R.layout.textview, new String[]{"name","listimageview"}, new int[]{R.id.houseText,R.id.listimageview}); return listadapter ; } private void ShowListView(){ mp3Infos=pares(R.raw.information); SimpleAdapter listadapter= budildSimpleAdapter(mp3Infos); setListAdapter(listadapter); } public List pares(Object xmlname){ List info=new ArrayList(); try { SAXParserFactory factory=SAXParserFactory.newInstance(); XMLReader reader=factory.newSAXParser().getXMLReader(); MyContentHandler mycontenthandler=new MyContentHandler(info); reader.setContentHandler(mycontenthandler); reader.parse(new InputSource(getResources().openRawResource((Integer) xmlname))); } catch (Exception e) { e.printStackTrace(); } return info; } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub //MyInfo myinfo=mp3Infos.get(position); //System.out.println("myinfo-------" myinfo); Intent intent =new Intent(); switch(position){ case 0: intent.setClass(WareHouseActivity.this, SMSapologize.class); startActivity(intent); break; case 1: intent.setClass(WareHouseActivity.this, SMSmylove.class); startActivity(intent); break; case 2: intent.setClass(WareHouseActivity.this, SMSlovewords.class); startActivity(intent); break; case 3: intent.setClass(WareHouseActivity.this, SMSHavefanTab.class); startActivity(intent); break; case 4: intent.setClass(WareHouseActivity.this, SMSLoverTab.class); startActivity(intent); break; case 5: intent.setClass(WareHouseActivity.this, SMSplayful.class); startActivity(intent); break; case 6: intent.setClass(WareHouseActivity.this, SMSBsharpturn.class); startActivity(intent); break; case 7: intent.setClass(WareHouseActivity.this, SMShumorjokes.class); startActivity(intent); break; case 8: intent.setClass(WareHouseActivity.this, SMSFriendTab.class); startActivity(intent); break; case 9: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 10: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 11: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 12: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 13: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 14: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 15: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; case 16: intent.setClass(WareHouseActivity.this, SMSSchooljoke.class); startActivity(intent); break; } super.onListItemClick(l, v, position, id); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode==KeyEvent.KEYCODE_BACK&&event.getRepeatCount()==0){ //需要处理 Intent intent =new Intent(); intent.setClass(WareHouseActivity.this, InformationActivityActivity.class); startActivity(intent); finish(); } return false; } class backlistener implements Button.OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(); intent.setClass(WareHouseActivity.this,InformationActivityActivity.class); startActivity(intent); finish(); }} class updatalistener implements Button.OnClickListener{ @Override public void onClick(View v) { ShowListView(); }}}
    2014-11-09下载
    积分:1
  • android 百度地图各种实例源码下载(可用)
    android 百度地图 源码
    2014-05-24下载
    积分:1
  • android 白天黑夜模式切换例子源码
    android 白天黑夜模式切换例子源码
    2014-09-28下载
    积分:1
  • android 仪表盘源码下载
    android 仪表盘源码下载
    2014-09-05下载
    积分:1
  • android 蓝牙连接打印机实例源码下载
    android 蓝牙连接打印机实例源码下载
    2014-08-26下载
    积分:1
  • android 数字滚动 wheel示例源码下载
    android 数字滚动 wheel示例源码下载
    2014-07-24下载
    积分:1
  • android 侧滑菜单 实例源码
    android 侧滑菜单 实例源码
    2014-05-30下载
    积分:1
  • android 监听自身被卸载 例子源码
    android 监听自身被卸载 例子源码
    2014-09-23下载
    积分:1
  • 植物大战僵尸 游戏源码下载
    植物大战僵尸 游戏源码下载
    2013-12-31下载
    积分:1
  • 可收缩界面控件
    可收缩界面控件
    2013-05-30下载
    积分:1
  • 696518资源总数
  • 104226会员总数
  • 29今日下载