2015-06-23 4 views
8

Ich habe ein Problem mit Picasso, der versucht, große Bilder von einem lokalen Uri des Formats zu laden Inhalt: //com.android.providers.media.documents/document/ imageXXYYZZ sowohl aus Galerie und Kamera Intent.Picasso kann keine großen Bilder laden (von Kamera und lokalem Uri)

ich die Bilder mit einem Standard-Aufruf bin Laden:

Picasso.load(image_url) 
     .resize(600, 240) 
     .centerCrop() 
     .into(imageTarget); 

Ich legte hier ein Target und wenn ich löste die onBitmapFailed(Drawable errorDrawable) Störung erhalten. Auch, wenn ich Picasso log ich:

06-23 12:13:54.267 22393-22393/it.b3lab.friendipity D/Picasso﹕ Main  created  [R100] Request{content://com.android.providers.media.documents/document/image%3A13345 resize(600,240) centerCrop} 
06-23 12:13:54.277 22393-23010/it.b3lab.friendipity D/Picasso﹕ Dispatcher enqueued  [R100]+9ms 
06-23 12:13:54.285 22393-23038/it.b3lab.friendipity D/Picasso﹕ Hunter  executing [R100]+15ms 
06-23 12:13:54.813 22393-23010/it.b3lab.friendipity D/Picasso﹕ Dispatcher batched  [R100]+546ms for error 
06-23 12:13:55.014 22393-23010/it.b3lab.friendipity D/Picasso﹕ Dispatcher delivered [R100]+746ms 
06-23 12:13:55.024 22393-22393/it.b3lab.friendipity I/picasso﹕ failed to load bitmap 
06-23 12:13:55.024 22393-22393/it.b3lab.friendipity D/Picasso﹕ Main  errored  [R100]+756ms 

Dies geschieht nur, wie ich oben sagte, wenn ich versuche, große Bilder aus der Galerie zu laden (über etwa 1 MB) und von der Kamera Absicht, wenn ein Hallo-res mit Kamera Smartphone (in meinem Fall ist es ein Moto G mit Android 5.0.1). Ich bekomme diesen Fehler nicht mit einem Samsung S2 auf Android 4.4.

Jede Hilfe würde wirklich geschätzt werden! Dank

Antwort

-1

Try this:

Uri uri = Uri.parse(imageUri); 
Picasso.with(context) 
    .load(uri) 
    .fit() 
    .resize(600, 240) 
    .skipMemoryCache() 
    .transform(new DocumentExifTransformation(this, uri)) 
    .into(imageView); 

Wenn ich hier einen Blick nicht funktioniert https://github.com/square/picasso/issues/539

3

Sie müssen den Inhalt uri zu einem absolut uri lösen. ZB wie folgt:

+0

Dank für Sie beantworten, aber mit dieser Methode Picasso laden kein Bild. Ich vermute, das Problem könnte sein, dass 'MediaStore.Images.Media.DATA' eingestellt werden sollte, wo ich das Bild richtig gespeichert habe? –

+0

Korrigieren. Der Spaltenname kann variieren. – Moritz

+0

In welche Spalte soll ich schauen? Ich speichere das Image in 'File (Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES)'), und der Imagetyp ist 'MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE' –

2

Ich habe viel Zeit damit verbracht, herauszufinden, wie man ein großes Bild mit Picasso in die Bildansicht lädt. Es arbeitete an Genymotion, aber arbeitete nicht an meinem Moto x. So entschied ich mich schließlich, das Bild innerhalb einer asynchronen Aufgabe manuell zu vergrößern und es dann in die Bildansicht zu laden, ohne Picasso zu verwenden.

new AsyncTask<String, Void, Void>() { 
       @Override 
       protected Void doInBackground(String... params) { 
        String path = params[0]; 
        final Bitmap resizedBitmap = ImageUtils.getResizedBitmap(200, 200, PATH_TO_IMAGE); 
        getActivity().runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          imageView.setImageBitmap(resizedBitmap); 
         } 
        }); 
        return null; 
       } 
      }.execute(imageLoadPath); 

können Sie ImageUtils.getResizedBitmap() Methode finden here

0

Picasso nicht aber das funktioniert perfekt

public static void resizeImage(String file, int maxTargetWidth, int maxTargetHeight) { 
    try { 
     InputStream in = new FileInputStream(file); 

     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(in, null, options); 
     close(in); 

     int inWidth = options.outWidth; 
     int inHeight = options.outHeight; 

     in = new FileInputStream(file); 
     options = new BitmapFactory.Options(); 
     options.inSampleSize = Math.max(inWidth/maxTargetWidth, inHeight/maxTargetHeight); 
     Bitmap roughBitmap = BitmapFactory.decodeStream(in, null, options); 

     Matrix m = new Matrix(); 
     RectF inRect = new RectF(0, 0, roughBitmap.getWidth(), roughBitmap.getHeight()); 
     RectF outRect = new RectF(0, 0, maxTargetWidth, maxTargetHeight); 
     m.setRectToRect(inRect, outRect, CENTER); 
     float[] values = new float[9]; 
     m.getValues(values); 

     Bitmap resizedBitmap = createScaledBitmap(roughBitmap, 
       (int) (roughBitmap.getWidth() * values[0]), (int) (roughBitmap.getHeight() * values[4]), 
       true); 

     resizedBitmap = rotateBitmap(file, resizedBitmap); 
     FileOutputStream out = new FileOutputStream(file); 
     resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out); 
     close(out); 
    } catch (Exception e) { 
     error(e); 
    } 
} 

private static Bitmap rotateBitmap(String src, Bitmap bitmap) { 
    try { 
     int orientation = new ExifInterface(src).getAttributeInt(TAG_ORIENTATION, 1); 
     Matrix matrix = new Matrix(); 
     if (orientation == ORIENTATION_NORMAL) return bitmap; 
     if (orientation == ORIENTATION_FLIP_HORIZONTAL) matrix.setScale(-1, 1); 
     else if (orientation == ORIENTATION_ROTATE_180) matrix.setRotate(180); 
     else if (orientation == ORIENTATION_FLIP_VERTICAL) { 
      matrix.setRotate(180); 
      matrix.postScale(-1, 1); 
     } else if (orientation == ORIENTATION_TRANSPOSE) { 
      matrix.setRotate(90); 
      matrix.postScale(-1, 1); 
     } else if (orientation == ORIENTATION_ROTATE_90) { 
      matrix.setRotate(90); 
     } else if (orientation == ORIENTATION_TRANSVERSE) { 
      matrix.setRotate(-90); 
      matrix.postScale(-1, 1); 
     } else if (orientation == ORIENTATION_ROTATE_270) { 
      matrix.setRotate(-90); 
     } else return bitmap; 
     try { 
      Bitmap oriented = createBitmap(bitmap, 0, 0, 
        bitmap.getWidth(), bitmap.getHeight(), matrix, true); 
      bitmap.recycle(); 
      return oriented; 
     } catch (OutOfMemoryError e) { 
      error(e); 
     } 
    } catch (IOException e) { 
     error(e); 
    } 
    return bitmap; 
} 
Verwandte Themen