没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
3页
本文实例讲述了Android编程调用Camera和相册功能。分享给大家供大家参考,具体如下: xml: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical> <Button android:id=@+id/button_cameraButton android:
资源详情
资源评论
资源推荐
Android编程调用编程调用Camera和相册功能详解和相册功能详解
本文实例讲述了Android编程调用Camera和相册功能。分享给大家供大家参考,具体如下:
xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button_cameraButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="拍照" />
<Button
android:id="@+id/button_photoButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="相册" />
<ImageView
android:id="@+id/imageview_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />
</LinearLayout>
activity:
package com.wj.cameratest;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class CameraShowActivity extends Activity {
private ImageView mImageView;
private Button mButtonCamera;
private Button mButtonPhoto;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_show);
mImageView = (ImageView) this.findViewById(R.id.imageview_preview);
mButtonCamera = (Button) this.findViewById(R.id.button_cameraButton);
mButtonPhoto = (Button) this.findViewById(R.id.button_photoButton);
mButtonCamera.setOnClickListener(new OnClickListener() { //打开Camera
@Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "camera.jpg")));
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
startActivityForResult(intent, 10);
}
});
mButtonPhoto.setOnClickListener(new OnClickListener() { //获取相册
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX",1);
intent.putExtra("aspectY",1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data",true);
weixin_38543293
- 粉丝: 7
- 资源: 963
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0