【问题标题】:how to set captured image on imageview如何在imageview上设置捕获的图像
【发布时间】:2015-04-22 07:58:58
【问题描述】:

如何使用 getData 设置在 imageview 上捕获的图像?当我运行它时,单击确定应用程序关闭。

 if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
             if (resultCode == RESULT_OK) {



                 Bitmap photo = (Bitmap) data.getExtras().get("data"); 
                 first_image.setImageBitmap(photo);


                 String[] projection = {};
                 Cursor cursor = getContentResolver().query(fileUri, projection, null, null, null);
                 int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                 cursor.moveToFirst();
                 String capturedImageFilePath = cursor.getString(column_index_data);

【问题讨论】:

    标签: java php android database android-studio


    【解决方案1】:

    你可以试试这个

    在获取路径后附加此代码

    File imgFile = new  File(capturedImageFilePath );
    
    if(imgFile.exists()){
    
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    
        ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
    
        myImage.setImageBitmap(myBitmap);
    
    }
    

    【讨论】:

      【解决方案2】:

      使用这个:

      if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
               if (resultCode == RESULT_OK) {
      Uri selectedImage = data.getData();
               Log.d("selectedimage", ""+selectedImage);
               String[] filePath = { MediaStore.Images.Media.DATA };
               Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);
               c.moveToFirst();
               int columnIndex = c.getColumnIndex(filePath[0]);
               String picturePath = c.getString(columnIndex);
               c.close();
               Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
      
               Log.w("path of image from gallery......******************.........", picturePath+"");
               ImageView m1= (ImageView)  findViewById(R.id.imageView1);
      }
      }
      

      【讨论】:

        【解决方案3】:

        你需要从数据中获取图片路径,你的代码应该是这样的:

        Uri uri = data.getData();
        String path = convertMediaUriToPath(getApplicationContext(), uri);
        Bitmap b = BitmapFactory.decodeFile(path);
        img.setImageBitmap(b);
        

        在哪里

        public String convertMediaUriToPath(Context context, Uri uri) {
            Cursor cursor = null;
            try {
                String[] proj = {MediaStore.MediaColumns.DATA};
                cursor = context.getApplicationContext()
                        .getContentResolver().query(uri, proj, null, null, null);
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
                cursor.moveToFirst();
                String path = cursor.getString(column_index);
                Log.e("path", path);
                return path;
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
        

        希望这会有所帮助:)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-09-19
          • 2014-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-27
          相关资源
          最近更新 更多