首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >设置ImageView位图没有显示任何内容

设置ImageView位图没有显示任何内容
EN

Stack Overflow用户
提问于 2015-08-29 11:13:08
回答 1查看 215关注 0票数 0

我用下面的密码来拍照。标记图片将被保存,但设置它的URI或位图将不显示任何内容。我该如何解决这个问题?

注释:下面的代码是一些方法和重写的方法。

代码语言:javascript
运行
复制
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);
    }
EN

回答 1

Stack Overflow用户

发布于 2015-08-29 11:21:57

嗨试试这个..。

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
    File imgFile = new File(iv_path);

            if (imgFile.exists()) {

                myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                iv_prpfile.setImageBitmap(myBitmap);
                iv_back.setImageBitmap(myBitmap);
            }

快乐编码:-)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32285379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档