Android-实现简单照相与摄像
来源:互联网 发布:java大学简明教程下载 编辑:程序博客网 时间:2024/04/27 16:14
布局:
<span style="font-family:KaiTi_GB2312;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动拍照程序" android:onClick="image" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动摄像程序" android:onClick="video" /></LinearLayout></span>
MainActivity.java
<span style="font-family:KaiTi_GB2312;font-size:18px;">import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore;import android.view.View;import android.widget.Toast;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void image(View v){//启动系统提供的拍照activityIntent intent = new Intent();intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//将拍照文件放入intentintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image1.jpg")));startActivityForResult(intent, 10);}public void video(View v){//启动系统提供的摄像activityIntent intent = new Intent();intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);//将摄像文件放入intentintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "video1.3gp")));intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);startActivityForResult(intent, 20);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);if(requestCode == 10){Toast.makeText(this, "拍照成功", 0).show();}else if(requestCode == 20){Toast.makeText(this, "摄像成功", 0).show();}}}</span>
0 0
- Android-实现简单照相与摄像
- Art&Science 摄像/照相/
- Android中调用设备的照相和摄像功能
- Android简单调用相机Camera功能,实现打开照相功能
- Android---简单的摄像程序
- android启动照相与录像
- Android中用MediaRecorder实现摄像
- Android学习笔记——简单实现照相、录音和录像功能
- Android调用Camera实现自定义照相
- android调用camera实现自定义照相
- Android系列之照相功能的实现
- 照相Android
- android照相
- android 照相
- android 照相
- Android--调用系统照相机拍照与摄像
- Android--调用系统照相机拍照与摄像
- android之照相、相册裁剪功能的实现过程
- hdu1249三角形(递推)
- cornerHarris函数
- swift 异常处理
- HDU 3579 Hello Kiki(中国剩余定理)
- 数据库知识总结---面试笔试
- Android-实现简单照相与摄像
- 20w买来的经验
- ESP8266学习笔记7:保存和读取自定义参数
- LeetCode_Remove Nth Node From End of List
- Badboy自动化测试工具 读取Excel
- java.util.ConcurrentModificationException 解决办法
- Pin instrumentation工具安装问题(command not found)
- android 截屏
- 没有JPEGEncoderOptions的解决方法