當前位置: 首頁>>代碼示例>>Java>>正文


Java BitmapFactory.decodeFileDescriptor方法代碼示例

本文整理匯總了Java中android.graphics.BitmapFactory.decodeFileDescriptor方法的典型用法代碼示例。如果您正苦於以下問題:Java BitmapFactory.decodeFileDescriptor方法的具體用法?Java BitmapFactory.decodeFileDescriptor怎麽用?Java BitmapFactory.decodeFileDescriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.BitmapFactory的用法示例。


在下文中一共展示了BitmapFactory.decodeFileDescriptor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decodeFileDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:17,代碼來源:BitmapManager.java

示例2: decodeSampledBitmapFromDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:42,代碼來源:ImageResizer.java

示例3: decodeSampledBitmapFromDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:liuyanggithub,項目名稱:SuperSelector,代碼行數:42,代碼來源:ImageResizer.java

示例4: decodeSampledBitmapFromDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:19,代碼來源:BitmapDecoder.java

示例5: decodeBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
}
 
開發者ID:mirhoseini,項目名稱:bcg,代碼行數:20,代碼來源:ImagePicker.java

示例6: decodeSampledBitmapFromFileDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:leibing8912,項目名稱:JkImageLoader,代碼行數:41,代碼來源:ImageResizer.java

示例7: originalDecodeFileDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
@DoNotStrip
private static Bitmap originalDecodeFileDescriptor(
    FileDescriptor fd,
    Rect outPadding,
    BitmapFactory.Options opts) {
  return BitmapFactory.decodeFileDescriptor(fd, outPadding, opts);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:WebpBitmapFactoryImpl.java

示例8: getWidthBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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);
}
 
開發者ID:ChangsenLai,項目名稱:codedemos,代碼行數:14,代碼來源:BitmapUtil.java

示例9: decodeSampledBitmapFromDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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);
    }
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:13,代碼來源:BitmapDecoder.java

示例10: getBitpMap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:30,代碼來源:PhotoUtil.java

示例11: decodeFileDescriptor

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:12,代碼來源:BitmapDecoder.java

示例12: getBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
}
 
開發者ID:mohammedirfan655,項目名稱:document-scanner,代碼行數:12,代碼來源:PickImageFragment.java

示例13: putImageInfo

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:41,代碼來源:CameraRollManager.java

示例14: decodeSampledBitmapFromUri

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
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;
        }

    }
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:34,代碼來源:ImageHelper.java

示例15: getBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 獲取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);
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:20,代碼來源:ImageUtils.java


注:本文中的android.graphics.BitmapFactory.decodeFileDescriptor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。