Ejemplo n.º 1
0
 public static BitmapRegionDecoder createBitmapRegionDecoder(
     JobContext jc, FileDescriptor fd, boolean shareable) {
   try {
     return BitmapRegionDecoder.newInstance(fd, shareable);
   } catch (Throwable t) {
     Log.w(TAG, t);
     return null;
   }
 }
Ejemplo n.º 2
0
 public static BitmapRegionDecoder createBitmapRegionDecoder(
     JobContext jc, String filePath, boolean shareable) {
   try {
     return BitmapRegionDecoder.newInstance(filePath, shareable);
   } catch (Throwable t) {
     Log.w(TAG, t);
     return null;
   }
 }
Ejemplo n.º 3
0
 public static BitmapRegionDecoder createBitmapRegionDecoder(
     JobContext jc, InputStream is, boolean shareable) {
   try {
     return BitmapRegionDecoder.newInstance(is, shareable);
   } catch (Throwable t) {
     // We often cancel the creating of bitmap region decoder,
     // so just log one line.
     Log.w(TAG, "requestCreateBitmapRegionDecoder: " + t);
     return null;
   }
 }
Ejemplo n.º 4
0
 public static Bitmap decodeThumbnail(
     JobContext jc, String filePath, Options options, int targetSize, int type) {
   FileInputStream fis = null;
   try {
     fis = new FileInputStream(filePath);
     FileDescriptor fd = fis.getFD();
     return decodeThumbnail(jc, fd, options, targetSize, type);
   } catch (Exception ex) {
     Log.w(TAG, ex);
     return null;
   } finally {
     Utils.closeSilently(fis);
   }
 }
Ejemplo n.º 5
0
  public static BitmapRegionDecoder createBitmapRegionDecoder(
      JobContext jc, byte[] bytes, int offset, int length, boolean shareable) {
    if (offset < 0 || length <= 0 || offset + length > bytes.length) {
      throw new IllegalArgumentException(
          String.format("offset = %s, length = %s, bytes = %s", offset, length, bytes.length));
    }

    try {
      return BitmapRegionDecoder.newInstance(bytes, offset, length, shareable);
    } catch (Throwable t) {
      Log.w(TAG, t);
      return null;
    }
  }
Ejemplo n.º 6
0
  // This is the same as the method above except the source data comes
  // from a file descriptor instead of a byte array.
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public static Bitmap decodeUsingPool(
      JobContext jc, FileDescriptor fileDescriptor, Options options) {
    if (options == null) options = new BitmapFactory.Options();
    if (options.inSampleSize < 1) options.inSampleSize = 1;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    options.inBitmap =
        (options.inSampleSize == 1) ? findCachedBitmap(jc, fileDescriptor, options) : null;
    try {
      Bitmap bitmap = DecodeUtils.decode(jc, fileDescriptor, options);
      if (options.inBitmap != null && options.inBitmap != bitmap) {
        GalleryBitmapPool.getInstance().put(options.inBitmap);
        options.inBitmap = null;
      }
      return bitmap;
    } catch (IllegalArgumentException e) {
      if (options.inBitmap == null) throw e;

      Log.w(TAG, "decode fail with a given bitmap, try decode to a new bitmap");
      GalleryBitmapPool.getInstance().put(options.inBitmap);
      options.inBitmap = null;
      return decode(jc, fileDescriptor, options);
    }
  }