显示在Android上的图像视图布局拍摄的最新画面 [英] Display the latest picture taken in the image view layout in android

查看:73
本文介绍了显示在Android上的图像视图布局拍摄的最新画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用程序,需要的图片与我的相机,并显示在我的图像视图工作layout.So任何人能告诉我如何访问所采取的最新画面,并显示它。

I am working on a app that takes a picture with my camera and shows it in my image view layout.So any one can tell me how to access the latest picture taken and display it.

推荐答案

我得到了解决,如果任何人有同样的问题ü可以参考这个

i got the solution if anyone have the same problem u can consult this

public void click1(View v){
    //define the file-name to save photo taken by Camera activity
    capturedImageFilePath=null;
    fileName = System.currentTimeMillis()+"";
    //create parameters for Intent with filename
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, fileName);
    values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
    //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
    imageUri = getContentResolver().insert(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    //create new Intent
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);


    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            //use imageUri here to access the image
             String[] projection = { MediaStore.Images.Media.DATA}; 
                Cursor cursor = managedQuery(imageUri, projection, null, null, null); 
                int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
                cursor.moveToFirst(); 
                capturedImageFilePath = cursor.getString(column_index_data);
                imageFile = new File(capturedImageFilePath);
                if(imageFile.exists()){
                    Bitmap bm = BitmapFactory.decodeFile(capturedImageFilePath);
                    image.setImageBitmap(bm);}
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
        } else {
            Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
        }
    }
    }

这篇关于显示在Android上的图像视图布局拍摄的最新画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆