我使用以下代码拍照。令牌图片将被保存,但设置其URI或位图不显示任何内容。我该如何解决这个问题?
注意:以下代码是一些方法和重写方法。
public static void takePicture(Activity activity) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = Images.createTempFile();
} catch (IOException e) {
Logger.log(activity, e);
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
activity.startActivityForResult(takePictureIntent, Constants.RequestCodes.IMAGE_CAPTURE);
}
}
}
public static Uri getUriFromFileName(String fileName) {
return Uri.fromFile(new File(fileName));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.RequestCodes.IMAGE_CAPTURE && resultCode == RESULT_OK) {
addViewToContainer(Images.getUriFromFileName(Logged.General
.getTempTakePhotoFilePath()));
}
}
private void addViewToContainer(Uri result) {
ImageView imageView = new ImageView(this);
Bitmap bitmap = null;
Uri uri = result == null ? Images.getUriFromFileName(Logged.General
.getTempTakePhotoFilePath()) : result;
try {
bitmap = MediaStore.Images.Media.getBitmap(getApplicationContext()
.getContentResolver(), uri);
} catch (IOException e) {
Logger.log(this, e);
}
imageView.setImageBitmap(bitmap);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LinearLayout.LayoutParams
.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
imageView.setLayoutParams(params);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setAdjustViewBounds(true);
mContainerLayout.removeAllViews();
mContainerLayout.setForeground(null);
mContainerLayout.addView(imageView);
}
答案 0 :(得分:0)
嗨试试这个......
private void openCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
String currentTimeStamp = dateFormat.format(new Date());
f = new File(android.os.Environment.getExternalStorageDirectory(), currentTimeStamp);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
try {
String click = f.getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
现在你得到文件PAth的生成图像然后
File imgFile = new File(iv_path);
if (imgFile.exists()) {
myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
iv_prpfile.setImageBitmap(myBitmap);
iv_back.setImageBitmap(myBitmap);
}
快乐编码: - )