Java Code Examples for android.graphics.BitmapFactory.decodeFileDescriptor()

The following are Jave code examples for showing how to use decodeFileDescriptor() of the android.graphics.BitmapFactory class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: MyAnimeViewer   File: BitmapManager.java   Source Code and License Vote up 6 votes
public Bitmap decodeFileDescriptor(FileDescriptor fd, BitmapFactory.Options options) {
    if (options.mCancel) {
        return null;
    }

    Thread thread = Thread.currentThread();
    if (!canThreadDecoding(thread)) {
        return null;
    }

    setDecodingOptions(thread, options);
    Bitmap b = BitmapFactory.decodeFileDescriptor(fd, null, options);

    removeDecodingOptions(thread);
    return b;
}
 
Example 2
Project: GCSApp   File: ImageResizer.java   Source Code and License Vote up 6 votes
/**
 * Decode and sample down a bitmap from a file input stream to the requested
 * width and height.
 * 
 * @param fileDescriptor
 *            The file descriptor to read from
 * @param reqWidth
 *            The requested width of the resulting bitmap
 * @param reqHeight
 *            The requested height of the resulting bitmap
 * @param cache
 *            The ImageCache used to find candidate bitmaps for use with
 *            inBitmap
 * @return A bitmap sampled down from the original with the same aspect
 *         ratio and dimensions that are equal to or greater than the
 *         requested width and height
 */
public static Bitmap decodeSampledBitmapFromDescriptor(
		FileDescriptor fileDescriptor, int reqWidth, int reqHeight,
		ImageCache cache) {

	// First decode with inJustDecodeBounds=true to check dimensions
	final BitmapFactory.Options options = new BitmapFactory.Options();
	options.inJustDecodeBounds = true;
	BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

	// Calculate inSampleSize
	options.inSampleSize = calculateInSampleSize(options, reqWidth,
			reqHeight);

	// Decode bitmap with inSampleSize set
	options.inJustDecodeBounds = false;

	// If we're running on Honeycomb or newer, try to use inBitmap
	if (Utils.hasHoneycomb()) {
		addInBitmapOptions(options, cache);
	}

	return BitmapFactory
			.decodeFileDescriptor(fileDescriptor, null, options);
}
 
Example 3
Project: SuperSelector   File: ImageResizer.java   Source Code and License Vote up 6 votes
/**
 * Decode and sample down a bitmap from a file input stream to the requested
 * width and height.
 * 
 * @param fileDescriptor
 *            The file descriptor to read from
 * @param reqWidth
 *            The requested width of the resulting bitmap
 * @param reqHeight
 *            The requested height of the resulting bitmap
 * @param cache
 *            The ImageCache used to find candidate bitmaps for use with
 *            inBitmap
 * @return A bitmap sampled down from the original with the same aspect
 *         ratio and dimensions that are equal to or greater than the
 *         requested width and height
 */
public static Bitmap decodeSampledBitmapFromDescriptor(
           FileDescriptor fileDescriptor, int reqWidth, int reqHeight,
           ImageCache cache) {

	// First decode with inJustDecodeBounds=true to check dimensions
	final BitmapFactory.Options options = new BitmapFactory.Options();
	options.inJustDecodeBounds = true;
	BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

	// Calculate inSampleSize
	options.inSampleSize = calculateInSampleSize(options, reqWidth,
			reqHeight);

	// Decode bitmap with inSampleSize set
	options.inJustDecodeBounds = false;

	// If we're running on Honeycomb or newer, try to use inBitmap
	if (Utils.hasHoneycomb()) {
		addInBitmapOptions(options, cache);
	}

	return BitmapFactory
			.decodeFileDescriptor(fileDescriptor, null, options);
}
 
Example 4
Project: Hotspot-master-devp   File: BitmapDecoder.java   Source Code and License Vote up 6 votes
public static Bitmap decodeSampledBitmapFromDescriptor(FileDescriptor fileDescriptor, BitmapSize maxSize, Bitmap.Config config) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inPurgeable = true;
    options.inInputShareable = true;
    BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    options.inSampleSize = calculateInSampleSize(options, maxSize.getWidth(), maxSize.getHeight());
    options.inJustDecodeBounds = false;
    if (config != null) {
        options.inPreferredConfig = config;
    }
    try {
        return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
        return null;
    }
}
 
Example 5
Project: JkImageLoader   File: ImageResizer.java   Source Code and License Vote up 5 votes
/**
 * get bitmap from filedescriptor
 * @author leibing
 * @createTime 2017/3/2
 * @lastModify 2017/3/2
 * @param fd
 * @param reqWidth
 * @param reqHeight
 * @return
 */
public static Bitmap decodeSampledBitmapFromFileDescriptor(FileDescriptor fd, int reqWidth, int reqHeight) {
	// bitmap soft ref
	SoftReference<Bitmap> bitmapSoftRef;
	// first decode with injustdecodebounds=true to check dimensions
	final BitmapFactory.Options options = new BitmapFactory.Options();
	try {
		options.inJustDecodeBounds = true;
		BitmapFactory.decodeFileDescriptor(fd, null, options);
		// calculate insamplesize
		options.inSampleSize = calculateInSampleSize(options, reqWidth,
				reqHeight);
		// decode bitmap with insamplesize set
		options.inJustDecodeBounds = false;
		// bitmap soft ref
		bitmapSoftRef
				= new SoftReference<Bitmap>(BitmapFactory.decodeFileDescriptor(fd, null, options));
		if (bitmapSoftRef != null && bitmapSoftRef.get() != null)
			return bitmapSoftRef.get();
	}catch (OutOfMemoryError ex){
		// add sample size
		options.inSampleSize = options.inSampleSize * 4;
		options.inJustDecodeBounds = false;
		// bitmap soft ref
		bitmapSoftRef
				= new SoftReference<Bitmap>(BitmapFactory.decodeFileDescriptor(fd, null, options));
		if (bitmapSoftRef != null && bitmapSoftRef.get() != null)
			return bitmapSoftRef.get();
	}
	return null;
}
 
Example 6
Project: GitHub   File: WebpBitmapFactoryImpl.java   Source Code and License Vote up 5 votes
@DoNotStrip
private static Bitmap originalDecodeFileDescriptor(
    FileDescriptor fd,
    Rect outPadding,
    BitmapFactory.Options opts) {
  return BitmapFactory.decodeFileDescriptor(fd, outPadding, opts);
}
 
Example 7
Project: codedemos   File: BitmapUtil.java   Source Code and License Vote up 5 votes
public static Bitmap getWidthBitmap(String path, int width) throws Exception {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true; // 仅获得尺寸信息
    BitmapFactory.decodeFile(path, options);
    options.inSampleSize = options.outWidth / width; // 当<1的时候默认会设置为1
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    options.inInputShareable = true;

    // 生成bitmap
    FileInputStream fis = new FileInputStream(path);
    return BitmapFactory.decodeFileDescriptor(fis.getFD(), null, options);
}
 
Example 8
Project: Pluto-Android   File: BitmapDecoder.java   Source Code and License Vote up 5 votes
public static Bitmap decodeSampledBitmapFromDescriptor(FileDescriptor fileDescriptor, int reqWidth, int reqHeight) {

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inPurgeable = true;
        BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    }
 
Example 9
Project: Pluto-Android   File: PhotoUtil.java   Source Code and License Vote up 5 votes
public static Bitmap getBitpMap(Context context, Uri uri, Display display) {
	ParcelFileDescriptor pfd;
	try {
		pfd = context.getContentResolver().openFileDescriptor(uri, "r");
	} catch (IOException ex) {
		return null;
	}
	java.io.FileDescriptor fd = pfd.getFileDescriptor();
	BitmapFactory.Options options = new BitmapFactory.Options();
	// 先指定原始大小
	options.inSampleSize = 1;
	// 只进行大小判断
	options.inJustDecodeBounds = true;
	// 调用此方法得到options得到图片的大小
	BitmapFactory.decodeFileDescriptor(fd, null, options);
	// 我们的目标是在800pixel的画面上显示。
	// 所以需要调用computeSampleSize得到图片缩放的比例
	options.inSampleSize = computeSampleSize(options, display.getWidth(),
			display.getHeight());
	// OK,我们得到了缩放的比例,现在开始正式读入BitMap数据
	options.inJustDecodeBounds = false;
	options.inDither = false;
	options.inPreferredConfig = Bitmap.Config.ARGB_8888;

	// 根据options参数,减少所需要的内存
	Bitmap sourceBitmap = BitmapFactory.decodeFileDescriptor(fd, null,
			options);
	return sourceBitmap;
}
 
Example 10
Project: Hotspot-master-devp   File: BitmapDecoder.java   Source Code and License Vote up 5 votes
public static Bitmap decodeFileDescriptor(FileDescriptor fileDescriptor) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    options.inInputShareable = true;
    try {
        return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
        return null;
    }
}
 
Example 11
Project: document-scanner   File: PickImageFragment.java   Source Code and License Vote up 5 votes
private Bitmap getBitmap(Uri selectedimg) throws IOException {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 3;
    AssetFileDescriptor fileDescriptor = null;
    fileDescriptor =
            getActivity().getContentResolver().openAssetFileDescriptor(selectedimg, "r");
    Bitmap original
            = BitmapFactory.decodeFileDescriptor(
            fileDescriptor.getFileDescriptor(), null, options);
    return original;
}
 
Example 12
Project: bcg   File: ImagePicker.java   Source Code and License Vote up 5 votes
private static Bitmap decodeBitmap(Context context, Uri theUri, int sampleSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = sampleSize;

    AssetFileDescriptor fileDescriptor = null;
    try {
        fileDescriptor = context.getContentResolver().openAssetFileDescriptor(theUri, "r");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    Bitmap actuallyUsableBitmap = BitmapFactory.decodeFileDescriptor(
            fileDescriptor.getFileDescriptor(), null, options);

    Timber.d(options.inSampleSize + " sample method bitmap ... " +
            actuallyUsableBitmap.getWidth() + " " + actuallyUsableBitmap.getHeight());

    return actuallyUsableBitmap;
}
 
Example 13
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 5 votes
private static boolean putImageInfo(
    ContentResolver resolver,
    Cursor photos,
    WritableMap node,
    int idIndex,
    int widthIndex,
    int heightIndex) {
  WritableMap image = new WritableNativeMap();
  Uri photoUri = Uri.withAppendedPath(
      Images.Media.EXTERNAL_CONTENT_URI,
      photos.getString(idIndex));
  image.putString("uri", photoUri.toString());
  float width = -1;
  float height = -1;
  if (IS_JELLY_BEAN_OR_LATER) {
    width = photos.getInt(widthIndex);
    height = photos.getInt(heightIndex);
  }
  if (width <= 0 || height <= 0) {
    try {
      AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
      BitmapFactory.Options options = new BitmapFactory.Options();
      // Set inJustDecodeBounds to true so we don't actually load the Bitmap, but only get its
      // dimensions instead.
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFileDescriptor(photoDescriptor.getFileDescriptor(), null, options);
      photoDescriptor.close();

      width = options.outWidth;
      height = options.outHeight;
    } catch (IOException e) {
      FLog.e(ReactConstants.TAG, "Could not get width/height for " + photoUri.toString(), e);
      return false;
    }
  }
  image.putDouble("width", width);
  image.putDouble("height", height);
  node.putMap("image", image);
  return true;
}
 
Example 14
Project: Exoplayer2Radio   File: ImageHelper.java   Source Code and License Vote up 5 votes
private Bitmap decodeSampledBitmapFromUri(Uri imageUri, int reqWidth, int reqHeight) {

        Bitmap bitmap;
        ParcelFileDescriptor parcelFileDescriptor =  null;

        try {
            parcelFileDescriptor = mContext.getContentResolver().openFileDescriptor(imageUri, "r");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        if (parcelFileDescriptor != null) {
            FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();

            // decode with inJustDecodeBounds=true to check dimensions
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

            // calculate inSampleSize
            options.inSampleSize = calculateSampleParameter(options, reqWidth, reqHeight);

            // decode bitmap with inSampleSize set
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

            return bitmap;

        } else {
            return null;
        }

    }
 
Example 15
Project: LJFramework   File: ImageUtils.java   Source Code and License Vote up 5 votes
/**
 * 获取bitmap
 *
 * @param fd 文件描述
 * @param maxWidth 最大宽度
 * @param maxHeight 最大高度
 * @return bitmap
 */
public static Bitmap getBitmap(FileDescriptor fd, int maxWidth, int maxHeight) {
    if (fd == null) {
        return null;
    }
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFileDescriptor(fd, null, options);
    options.inSampleSize = calculateInSampleSize(options, maxWidth, maxHeight);
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFileDescriptor(fd, null, options);
}
 
Example 16
Project: GitHub   File: WebpBitmapFactoryImpl.java   Source Code and License Vote up 4 votes
@DoNotStrip
private static Bitmap originalDecodeFileDescriptor(FileDescriptor fd) {
  return BitmapFactory.decodeFileDescriptor(fd);
}
 
Example 17
Project: BaseCore   File: ImageUtils.java   Source Code and License Vote up 2 votes
/**
 * 获取bitmap
 *
 * @param fd 文件描述
 * @return bitmap
 */
public static Bitmap getBitmap(FileDescriptor fd) {
    if (fd == null) return null;
    return BitmapFactory.decodeFileDescriptor(fd);
}
 
Example 18
Project: Android-UtilCode   File: ImageUtils.java   Source Code and License Vote up 2 votes
/**
 * 获取bitmap
 *
 * @param fd 文件描述
 * @return bitmap
 */
public static Bitmap getBitmap(FileDescriptor fd) {
    if (fd == null) return null;
    return BitmapFactory.decodeFileDescriptor(fd);
}
 
Example 19
Project: AndroidUtilCode-master   File: ImageUtils.java   Source Code and License Vote up 2 votes
/**
 * 获取bitmap
 *
 * @param fd 文件描述
 * @return bitmap
 */
public static Bitmap getBitmap(FileDescriptor fd) {
    if (fd == null) return null;
    return BitmapFactory.decodeFileDescriptor(fd);
}
 
Example 20
Project: HeadlineNews   File: ImageUtils.java   Source Code and License Vote up 2 votes
/**
 * 获取bitmap
 *
 * @param fd 文件描述
 * @return bitmap
 */
public static Bitmap getBitmap(final FileDescriptor fd) {
    if (fd == null) return null;
    return BitmapFactory.decodeFileDescriptor(fd);
}