android摄像头拍照代码,Android调用摄像头拍照开发教程

本文介绍了如何在Android应用中实现拍照功能,包括布局文件和MainActivity.java的代码细节,涉及相机权限、图片存储以及4.4及以上系统的图片处理。通过示例代码展示了如何启动相机、获取照片并显示在ImageView上。
摘要由CSDN通过智能技术生成

现在很多应用中都会要求用户上传一张图片来作为头像,首先我在这接收使用相机拍照和在相册中选择图片。接下来先上效果图:

d2a53c34f6eb3866b70ddad97ba10ae7.png

805f070088990da8b1e29fa8135f7e0b.png

879c96a2d70f72b410222460695b30d6.png

9c5cb8f7de3d947e139ce05300e0fe0c.png

接下来看代码:

1、布局文件:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context="com.gyq.cameraalbumtest.MainActivity">

android:id="@+id/btn_take_photo"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="take photo"/>

android:id="@+id/choose_from_album"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="choose from album"/>

android:id="@+id/iv_picture"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"/>

2、MainActivity.java逻辑代码:

package com.gyq.cameraalbumtest;

import android.Manifest;

import android.annotation.TargetApi;

import android.content.ContentUris;

import android.content.Intent;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值