2016-04-30 2 views
-1

Wenn ich versuche, Bild aus der Galerie auszuwählen, gibt es mir eine Fehlermeldung Load Failed.In einigen Handys kommt es nur so (wie ein Plus) Can any Körper mir helfen, diese issue.Thank SieBild aus der Galerie auswählen, mir einen Fehler geben Load Failed

 private void openGalleryForImageSelection() 
{ 
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    try 
    { 
     startActivityForResult(intent, IMAGE_FROM_GALLERY); 
    } 
    catch(Throwable e) 
    { 
     Toast.makeText(this,getResources().getString(R.string.image_error),Toast.LENGTH_SHORT).show(); 
    } 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    if (((requestCode == IMAGE_FROM_GALLERY) || (requestCode == IMAGE_FROM_CAMERA)) && (Activity.RESULT_OK == resultCode)) 
    { 
     if (requestCode == IMAGE_FROM_GALLERY) 
     { 
      mImageCaptureUri = data.getData(); 
     } 
     cropTheImage(); 
     return; 
    } 
} 
+0

So zu lösen, wo ist der Code? – ianhanniballake

+0

Vielen Dank für Ihre Antwort. Ich habe meinen Code hinzugefügt. Können Sie mir bitte eine Lösung vorschlagen, um dieses Problem zu lösen? –

+0

wo ist cropTheImage() Funktion –

Antwort

0
void selectImage() {  
Intent intent = new Intent(
    Intent.ACTION_PICK, 
    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    intent.setType("image/*"); 
    startActivityForResult(
    Intent.createChooser(intent, "Select File"), 
    IMAGE_FROM_GALLERY); 
} 



protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == IMAGE_FROM_GALLERY && resultCode == RESULT_OK) { 
     Uri selectedImageUri = data.getData(); 
     String[] projection = { MediaColumns.DATA }; 
     CursorLoader cursorLoader = new CursorLoader(this,selectedImageUri, projection, null, null, 
     null); 
     Cursor cursor =cursorLoader.loadInBackground(); 
     int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); 
     cursor.moveToFirst(); 
     String selectedImagePath = cursor.getString(column_index); 
     Bitmap bm; 

     file = new File(selectedImagePath); 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeFile(selectedImagePath, options); 
     final int REQUIRED_SIZE = 200; 
     int scale = 1; 
     while (options.outWidth/scale/2 >= REQUIRED_SIZE 
     && options.outHeight/scale/2 >= REQUIRED_SIZE) 
     scale *= 2; 
     options.inSampleSize = scale; 
     options.inJustDecodeBounds = false; 
     bm = BitmapFactory.decodeFile(selectedImagePath, options); 
    } 
} 
0
private void openGallery() { 
    Intent intent = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), 
      PICK_IMAGE); 
} 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == PICK_IMAGE) { 

     try { 
      taken = "gallery"; 
      selectedImage = data.getData(); 
      String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

      cursor = getActivity().getContentResolver().query(selectedImage, 
        filePathColumn, null, null, null); 
      cursor.moveToFirst(); 
      columnindex = cursor.getColumnIndex(filePathColumn[0]); 
      file_path = cursor.getString(columnindex); 
      // Log.e("Attachment Path:", attachmentFile); 
      // tv_attach.setText(file_path); 
      URI = Uri.parse("file://" + file_path); 
      image_path = file_path; 
      cursor.close(); 
      if (resultCode == 0) { 
       dialog_camera.dismiss(); 
      } else { 
       dialog_camera.dismiss();  
      } 
     } catch (Exception e) { 
     } 
+0

Könnten Sie bitte erwähnen, was diese Änderungen sind und warum diese benötigt werden? –

Verwandte Themen