电脑
首先,找到AndroidManifest.xml文件里加入用户权限
其次,在主类java文件里加入2个控件(button和imageview),是用来触发按钮事件和显示图片的,final int TAKE_PICTURE = 1;//为了表示返回方法中辨识你的程序打开的相机。
输入关键词:startActivityForResult(new Intent('android.media.action.IMAGE_CAPTURE'), TAKE_PICTURE);
然后打开系统自带相机,以下是处理拍照得到的数据,将数据输入系统 protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_PICTURE) { if (resultCode == RESULT_OK) { Bitmap bm = (Bitmap) data.getExtras().get('data'); img.setImageBitmap(bm);//想图像显示在ImageView视图上,private ImageView img; File myCaptureFile = new File('sdcard/123456.jpg'); try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
采用压缩转档方法 bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);/* 调用flush()方法,更新BufferStream */bos.flush(); /* 结束OutputStream *bos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace()
相机重置 private void resetCamera()if (mCamera01 != null && bIfPreview mCamera01.stopPreview(); /* 扩展学习,释放Camera对象 */ mCamera01.release(); mCamera01 = null; bIfPreview = false;
上述方法来源于网络,感谢原文作者的分享,原文作者享有所有版权。
上述照片来源网络,可能与方法不符。