本文介绍了Android的 - 问题越来越图像URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
像标题说我的问题是关于相机拍摄图像的图像URI。开放的我们总是空...为什么?
@覆盖
公共无效的onClick(视图v){
意图cameraIntent =新的意图(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,TAKE_PICTURE);
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == TAKE_PICTURE)
{
//乌里contentURI = Uri.parse(data.getDataString());
。缩略图=(位图)data.getExtras()获得(数据);
ImageView的形象=(ImageView的)findViewById(R.id.photoResultView);
image.setImageBitmap(缩略图);
photoUri = data.getData();
Log.e(FOTOLOG,+ photoUri);
}
}
解决方案
看看这个,
的Android ACTION_IMAGE_CAPTURE意图
可能会为你提供一些见解。
公共无效startCamera(){
档案照片= NULL;
意向意图=新的意图(android.media.action.IMAGE_CAPTURE);
如果(android.os.Environment.getExternalStorageState()。等于(
android.os.Environment.MEDIA_MOUNTED)){
照片=新的文件(android.os.Environment
.getExternalStorageDirectory(),FILE_NAME);
} 其他 {
照片=新的文件(getCacheDir(),FILE_NAME);
}
如果(照片!= NULL){
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(照片));
selectedImageUri = Uri.fromFile(照片);
startActivityForResult(意向,IMAGE_CAPTURE);
}
}
公共无效onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == IMAGE_CAPTURE){
如果(结果code == Activity.RESULT_OK){
尝试 {
乌里selectedImage = selectedImageUri;
//getContentResolver().notifyChange(selectedImage,NULL);
ContentResolver的CR = getContentResolver();
点阵位图;
位= android.provider.MediaStore.Images.Media
.getBitmap(CR,selectedImage);
rptImage.setImageBitmap(位);
}赶上(例外五){
Toast.makeText(这一点,无法加载,Toast.LENGTH_SHORT)
。显示();
Log.e(相机,e.toString());
}
} 其他 {
selectedImageUri = NULL;
rptImage.setImageBitmap(空);
}
}
}
这是从我的应用程序中的code样本。
您所需要的权限,
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
<使用-权限的Android:名称=android.permission.CAMERA/>
<使用特征的android:NAME =android.hardware.camera/>
like the title says my problem concerns the image uri of images taken by the camera.Uri is always null ... WHY?
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, TAKE_PICTURE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == TAKE_PICTURE)
{
//Uri contentURI = Uri.parse(data.getDataString());
thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.photoResultView);
image.setImageBitmap(thumbnail);
photoUri = data.getData();
Log.e("FOTOLOG",""+ photoUri);
}
}
解决方案
Look at this,
Android ACTION_IMAGE_CAPTURE Intent
might provide you with some insight.
public void startCamera() {
File photo = null;
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
photo = new File(android.os.Environment
.getExternalStorageDirectory(), FILE_NAME);
} else {
photo = new File(getCacheDir(), FILE_NAME);
}
if (photo != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
selectedImageUri = Uri.fromFile(photo);
startActivityForResult(intent, IMAGE_CAPTURE);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IMAGE_CAPTURE) {
if (resultCode == Activity.RESULT_OK) {
try {
Uri selectedImage = selectedImageUri;
//getContentResolver().notifyChange(selectedImage, null);
ContentResolver cr = getContentResolver();
Bitmap bitmap;
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
rptImage.setImageBitmap(bitmap);
} catch (Exception e) {
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
.show();
Log.e("Camera", e.toString());
}
} else {
selectedImageUri = null;
rptImage.setImageBitmap(null);
}
}
}
That's a code sample from my application.
You need the permission,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
这篇关于Android的 - 问题越来越图像URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!