2016-09-08 14 views
-2

ギャラリーから画像を選択し、選択した画像をImageViewに配置します。私はIntentも持っており、カメラで撮影してImageViewに入れてうまくいきます。しかし、ギャラリーIntentはチューを開いているし、イメージを選択するが、それは、このエラーがギャラリーから選択したImageViewに画像を配置する

をE/OpenGLRendererまで来ているログにImageView

に置か取得されていません:SFEffectCache:クリア() 、MSIZE = 0

オープンギャラリー方法

private void openGallery() { 
    tvGallery.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Toast.makeText(getApplicationContext(), "Opening Gallery, Please wait..", Toast.LENGTH_SHORT).show(); 
      private int PICK_IMAGE_REQUEST = 1; 
      Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
      galleryIntent.setType("image/*"); 
      startActivityForResult(galleryIntent,PICK_IMAGE_REQUEST); 
      Log.e("Status:", "Photopicker canceled"); 


     } 
    }); 
} 

onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    super.onActivityResult(requestCode, resultCode, data); 
    /*camera preview*/ 
    if (resultCode == RESULT_OK) { 
     Bitmap bp = (Bitmap) data.getExtras().get("data"); 
     previewView.setImageBitmap(bp); 
    } 
    /*gallery preview*/ 
    else if (requestCode == PICK_IMAGE_REQUEST) { 
     if (resultCode == RESULT_OK) { 

      Uri selectedImage = data.getData(); 
      String[] filePathColumn = {MediaStore.Images.Media.DATA}; 
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
      cursor.moveToFirst(); 
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      String picturePath = cursor.getString(columnIndex); 
      cursor.close(); 
      previewView = (ImageView) findViewById(R.id.imgPostIssue); 
      previewView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
     } 

    } 
} 

ログエラー以下

09-08 15:40:02.355 30860-30860/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:03.836 30860-30860/bluecoppertech.com.taskmeld E/Status:: Photopicker canceled 
09-08 15:40:07.460 30860-30860/bluecoppertech.com.taskmeld E/OpenGLRenderer: SFEffectCache:clear(), mSize = 0 
09-08 15:40:21.754 30860-30860/bluecoppertech.com.taskmeld E/OpenGLRenderer: SFEffectCache:clear(), mSize = 0 
09-08 15:40:32.885 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.885 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.885 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.895 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.905 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.915 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.915 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.945 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.965 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.975 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:32.995 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method bluecoppertech.com.taskmeld.Activity.activity.utils.PostNewIssue.access$super 
09-08 15:40:33.225 32246-32246/bluecoppertech.com.taskmeld E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 
+0

あなたが質問をダウン投票し、質問と間違って何ですか? – Sampad

+0

ログエラーを表示しているものが間違っています!完全なログエラーを投稿できますか? –

+0

'android.os.PersistableBundle' – Sampad

答えて

0
@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     // TODO Auto-generated method stub 
     super.onActivityResult(requestCode, resultCode, data); 
     /*camera preview*/ 

     if (resultCode != RESULT_CANCELED) { 


      if (requestCode == 0) { 
       Bitmap bp = (Bitmap) data.getExtras().get("data"); 
       previewView.setImageBitmap(bp); 
      } 
     /*gallery preview*/ 
      else { 

       Uri uri = data.getData(); 

       try { 
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); 
        Log.d(TAG, String.valueOf(bitmap)); 


        ImageView previewView = (ImageView) findViewById(R.id.imgPostIssue); 
        previewView.setImageBitmap(bitmap); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 

     } 
    } 
0

は、ライブラリから写真を選択するか、カメラから1をキャプチャし、ImageViewの中でそれを使用しての作業溶液です。

出典:SO

//functions to select image from the device 
    private void selectImage() { 
     final CharSequence[] items = {"Take Photo","Choose from Library", "Cancel" }; 
     AlertDialog.Builder builder = new AlertDialog.Builder(signature_new.this); 
     builder.setTitle("Add Photo!"); 
     builder.setItems(items, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int item) { 
       if (items[item].equals("Take Photo")) { 
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        startActivityForResult(intent, REQUEST_CAMERA); 
       } else if (items[item].equals("Choose from Library")) { 
        Intent intent = new Intent(
          Intent.ACTION_PICK, 
          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
        intent.setType("image/*"); 
        startActivityForResult(
          Intent.createChooser(intent, "Select File"), 
          SELECT_FILE); 
       } else if (items[item].equals("Cancel")) { 
        dialog.dismiss(); 
       } 
      } 
     }); 
     builder.show(); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (resultCode == RESULT_OK) { 
      if (requestCode == REQUEST_CAMERA) { 
       Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); 
       ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
       thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); 

       File destination = new File(Environment.getExternalStorageDirectory(), 
         System.currentTimeMillis() + ".jpg"); 

       FileOutputStream fo; 
       try { 
        destination.createNewFile(); 
        fo = new FileOutputStream(destination); 
        fo.write(bytes.toByteArray()); 
        fo.close(); 
       } catch (FileNotFoundException e) { 
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 


       imageF.setImage(ImageSource.bitmap(thumbnail)); 

      } else if (requestCode == SELECT_FILE) { 
       Uri selectedImageUri = data.getData(); 
       try { 

        Bitmap bm=decodeUri(selectedImageUri); 
        imageViewF.setImage(ImageSource.bitmap(bm)); 
        //uploadbm=bm; 
        //dialog_dimension(); 
       } 
       catch(FileNotFoundException e) { 
        e.printStackTrace(); 
       } 

      } 
     } 
    } 
0

これはギャラリー

Intent Gallery_intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
        startActivityForResult(Gallery_intent, constants.RESULT_LOAD_IMAGE); 

を開くための意図であり、これは活動の結果に自分のコードを修正

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == constants.RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) { 
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = false; 
     options.inPreferredConfig = Bitmap.Config.RGB_565; 
     b = BitmapFactory.decodeFile(getRealPathFromURI(data.getData()), options); 
     int bmpHeight = b.getHeight(); 
     int bmpWidth = b.getWidth(); 
     if (bmpHeight > 1500) { 
      bmpHeight = bmpHeight/4; 
      bmpWidth = bmpWidth/4; 
     } 
     Bitmap out = Bitmap.createScaledBitmap(b, bmpWidth, bmpHeight, false); 

     File file = new File(dir, "resize.png"); 
     FileOutputStream fOut; 
     try { 
      fOut = new FileOutputStream(file); 
      out.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
      fOut.flush(); 
      fOut.close(); 
      b.recycle(); 
      out.recycle(); 
     } catch (Exception e) { 
     } 

     ImageView.setImageURI(Uri.fromFile(file)); 
    } 
0

です...あなたの条件でありますonActivityResultでかなり間違っています

private void openGallery() { 
    tvGallery.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Toast.makeText(getApplicationContext(), "Opening Gallery, Please wait..", Toast.LENGTH_SHORT).show(); 
      Intent intent = new Intent(); 
      // Show only images, no videos or anything else 
      intent.setType("image/*"); 
      intent.setAction(Intent.ACTION_GET_CONTENT); 
      // Always show the chooser (if there are multiple options available) 
      startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); 


     } 
    }); 
} 

あなたOnActivityResultギャラリー

private int PICK_IMAGE_REQUEST = 1;

private void openGallery() { 
     tvGallery.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent intent = new Intent(); 
       // Show only images, no videos or anything else 
       intent.setType("image/*"); 
       intent.setAction(Intent.ACTION_GET_CONTENT); 
       // Always show the chooser (if there are multiple options available) 
       startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); 


      } 
     }); 
    } 

OnActivityResult 012からImageViewに画像を配置する方法

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { 

     Uri uri = data.getData(); 

     try { 
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); 
      // Log.d(TAG, String.valueOf(bitmap)); 


      previewView = (ImageView) findViewById(R.id.imgPostIssue); 
      previewView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 


      ImageView previewView = (ImageView) findViewById(R.id.imgPostIssue); 
      previewView.setImageBitmap(bitmap); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

まだ動作していません。 – Sampad

関連する問題