多语言展示
当前在线:1784今日阅读:167今日分享:16

android 拍照如何实现水平仪

对于android 拍照如何实现水平仪,小编下面为大家介绍关于android 拍照如何实现水平仪,希望能够给大家带来帮助。
工具/原料

电脑

方法/步骤
1

首先,找到AndroidManifest.xml文件里加入用户权限  

2

其次,在主类java文件里加入2个控件(button和imageview),是用来触发按钮事件和显示图片的,final int TAKE_PICTURE = 1;//为了表示返回方法中辨识你的程序打开的相机。

3

输入关键词:startActivityForResult(new Intent('android.media.action.IMAGE_CAPTURE'), TAKE_PICTURE);

4

然后打开系统自带相机,以下是处理拍照得到的数据,将数据输入系统    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));

5

采用压缩转档方法 bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);/* 调用flush()方法,更新BufferStream */bos.flush(); /* 结束OutputStream *bos.close();    } catch (FileNotFoundException e) {     // TODO Auto-generated catch block     e.printStackTrace()

6

相机重置 private void resetCamera()if (mCamera01 != null && bIfPreview       mCamera01.stopPreview();       /* 扩展学习,释放Camera对象 */       mCamera01.release();       mCamera01 = null;       bIfPreview = false;

注意事项
1

上述方法来源于网络,感谢原文作者的分享,原文作者享有所有版权。

2

上述照片来源网络,可能与方法不符。

推荐信息