当前位置: 首页>>代码示例>>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;未经允许,请勿转载。