2024年5月4日发(作者:)
Android调用系统摄像头拍照,并把照片保存到本地,然后显示在Imageview
img=(ImageView)findViewById();
take_picture=(Button)findViewById(_picture);
take_lickListener(new kListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent( _CAPTURE
startActivityForResult(intent,T_KEYS_DIALER);
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
vityResult(requestCode, resultCode, data);
if (resultCode == _OK) {
String sdStatus = ernalStorageState();
if (!(_MOUNTED)) { // 检测sd是否可用
return;
Bundle bundle = ras();
Bitmap bitmap = (Bitmap) ( data // 获取相机返回的数据,并转换为Bitmap图片
格式
FileOutputStream b = null;
File file = new File( /sdcard/myImage/
();// 创建文件夹,名称为myimage
//照片的命名,目标文件夹下,以当前时间数字串为名称,即可确保每张照片名称不相同。
String str=null;
Date date=null;
SimpleDateFormat format = new SimpleDateFormat( yyyyMMddHHmmss //获取当前时间,
进一步转化为字符串
date =new Date();
str=(date);
String fileName = /sdcard/myImage/ +str+ .jpg
try {
b = new FileOutputStream(fileName);
ss(, 100, b);// 把数据写入文件
} catch (FileNotFoundException e) {
tackTrace();
} finally {
try {
();
();
} catch (IOException e) {
tackTrace();
if (data!= null) {
Bitmap cameraBitmap = (Bitmap) ras().get( data
n( fdf================= +aString());
geBitmap(cameraBitmap);
n( 成功====== +th()+ght());
}
发布评论