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


Java BitmapFactory.Options方法代碼示例

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


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

示例1: decodeSampledBitmapFromResource

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 根據計算的inSampleSize,得到壓縮後圖片
 * 
 * @param pathName
 * @param reqWidth
 * @param reqHeight
 * @return
 */
private Bitmap decodeSampledBitmapFromResource(String pathName,
                                                  int reqWidth, int reqHeight)
{
	// 第一次解析將inJustDecodeBounds設置為true,來獲取圖片大小
	final BitmapFactory.Options options = new BitmapFactory.Options();
	options.inJustDecodeBounds = true;
	BitmapFactory.decodeFile(pathName, options);
	// 調用上麵定義的方法計算inSampleSize值
	options.inSampleSize = calculateInSampleSize(options, reqWidth,
			reqHeight);
	// 使用獲取到的inSampleSize值再次解析圖片
	options.inJustDecodeBounds = false;
	Bitmap bitmap = BitmapFactory.decodeFile(pathName, options);

	return bitmap;
}
 
開發者ID:liuyanggithub,項目名稱:SuperSelector,代碼行數:25,代碼來源:ImageLoadUtil.java

示例2: decodeBitmapFromResLruCache

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 讀取圖片 優先從緩存中獲取圖片
 */
static BitmapDrawable decodeBitmapFromResLruCache(Resources resources, @RawRes int resId,
                                                  int reqWidth, int reqHeight,
                                                  ImageCache cache) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    decodeStream(resources.openRawResource(resId), null, options);
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    BitmapDrawable bitmapFromCache;
    String resourceName = resources.getResourceName(resId);
    bitmapFromCache = cache.getBitmapFromCache(resourceName);
    if (bitmapFromCache == null) {
        bitmapFromCache = readBitmapFromRes(resources, resId, cache, options);
        cache.addBitmapToCache(resourceName, bitmapFromCache);
    }

    return bitmapFromCache;
}
 
開發者ID:ronghao,項目名稱:FrameAnimationView,代碼行數:22,代碼來源:BitmapLoadUtil.java

示例3: getBitmapFromFile

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap getBitmapFromFile(File dst, int width, int height) {
    if (null != dst && dst.exists()) {
        BitmapFactory.Options opts = null;
        if (width > 0 && height > 0) {
            opts = new BitmapFactory.Options();
            opts.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(dst.getPath(), opts);
            final int minSideLength = Math.min(width, height);
            opts.inSampleSize = computeSampleSize(opts, minSideLength, width * height);
            opts.inJustDecodeBounds = false;
            opts.inInputShareable = true;
            opts.inPurgeable = true;
        }
        try {
            return BitmapFactory.decodeFile(dst.getPath(), opts);
        } catch (OutOfMemoryError e) {
            try {
                return BitmapFactory.decodeFile(dst.getPath(), opts);
            } catch (OutOfMemoryError e2) {
                e2.printStackTrace();
            }
        }
    }
    return null;
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:26,代碼來源:BitmapUtils.java

示例4: compressImage

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static void compressImage(String savePath, String filepath,
		int quality, Display display) {
	int scale = 1;
	BitmapFactory.Options options = new BitmapFactory.Options();
	options.inJustDecodeBounds = true;
	BitmapFactory.decodeFile(filepath, options);
	if (options.outWidth > IMAGE_MAX_WIDTH
			|| options.outHeight > IMAGE_MAX_HEIGHT) {
		scale = calculateInSampleSize(options, display.getWidth(),
				display.getHeight());
	}
	options.inJustDecodeBounds = false;
	options.inSampleSize = scale;
	Bitmap bitmap = BitmapFactory.decodeFile(filepath, options);
	Matrix matrix = new Matrix();
	matrix.setRotate(readPictureDegree(filepath));
	Bitmap saveBitmap = Bitmap.createBitmap(bitmap, 0, 0,
			bitmap.getWidth(), bitmap.getHeight(), matrix, true);
	writeToFile(savePath, saveBitmap, quality);
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:21,代碼來源:PhotoUtil.java

示例5: calculateInSampleSize

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static int calculateInSampleSize(BitmapFactory.Options options,
                                        int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        // Calculate ratios of height and width to requested height and
        // width
        final int heightRatio = Math.round((float) height
                / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will
        // guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;
    }

    return inSampleSize;
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:25,代碼來源:BitmapUitls.java

示例6: tryToGetBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private Bitmap tryToGetBitmap(File file, BitmapFactory.Options options, int rotate, boolean shouldScale) throws IOException, OutOfMemoryError {
    Bitmap bmp;
    if (options == null) {
        bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
    } else {
        bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
    }
    if (bmp == null) {
        throw new IOException("The image file could not be opened.");
    }
    if (options != null && shouldScale) {
        float scale = calculateScale(options.outWidth, options.outHeight);
        bmp = this.getResizedBitmap(bmp, scale);
    }
    if (rotate != 0) {
        Matrix matrix = new Matrix();
        matrix.setRotate(rotate);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    }
    return bmp;
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:22,代碼來源:MultiImageChooserActivity.java

示例7: createBitmapOptions

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * Lazily create {@link BitmapFactory.Options} based in given
 * {@link Request}, only instantiating them if needed.
 */
static BitmapFactory.Options createBitmapOptions(Request data) {
  final boolean justBounds = data.hasSize();
  final boolean hasConfig = data.config != null;
  BitmapFactory.Options options = null;
  if (justBounds || hasConfig || data.purgeable) {
    options = new BitmapFactory.Options();
    options.inJustDecodeBounds = justBounds;
    options.inInputShareable = data.purgeable;
    options.inPurgeable = data.purgeable;
    if (hasConfig) {
      options.inPreferredConfig = data.config;
    }
  }
  return options;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:RequestHandler.java

示例8: calculateInSampleSize

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (reqWidth <= 0 || reqHeight <= 0) {
        return 1;
    }

    if (height > reqHeight || width > reqWidth) {

        final int halfHeight = height / 2;
        final int halfWidth = width / 2;

        // Calculate the largest inSampleSize value that is a power of 2 and keeps both
        // height and width larger than the requested height and width.
        while ((halfHeight / inSampleSize) > reqHeight
                && (halfWidth / inSampleSize) > reqWidth) {
            inSampleSize *= 2;
        }
    }
    return inSampleSize;
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-android,代碼行數:25,代碼來源:ImageUtils.java

示例9: loadTexture

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private int loadTexture(int resId) {
    final int[] textureIds = new int[1];
    GLES20.glGenTextures(1, textureIds, 0);

    if (textureIds[0] == 0) return -1;

    // do not scale the bitmap depending on screen density
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;

    final Bitmap textureBitmap = BitmapFactory.decodeResource(getResources(), resId, options);
    attachBitmapToTexture(textureIds[0], textureBitmap);

    return textureIds[0];
}
 
開發者ID:PacktPublishing,項目名稱:Building-Android-UIs-with-Custom-Views,代碼行數:16,代碼來源:GLDrawer.java

示例10: decodeSampledBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap decodeSampledBitmap(String path,
                                         int reqWidth, int reqHeight) {

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

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

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(path, options);
}
 
開發者ID:HitRoxxx,項目名稱:FloatingNew,代碼行數:16,代碼來源:Utils.java

示例11: hookDecodeStream

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
@DoNotStrip
public static Bitmap hookDecodeStream(
    InputStream inputStream,
    Rect outPadding,
    BitmapFactory.Options opts) {
  StaticWebpNativeLoader.ensure();
  inputStream = wrapToMarkSupportedStream(inputStream);

  Bitmap bitmap;

  byte[] header = getWebpHeader(inputStream, opts);
  if (WebpSupportStatus.sIsWebpSupportRequired && isWebpHeader(header, 0, HEADER_SIZE)) {
    bitmap = nativeDecodeStream(
        inputStream,
        opts,
        getScaleFromOptions(opts),
        getInTempStorageFromOptions(opts));
    // We notify that the direct decoder failed
    if (bitmap == null) {
      sendWebpErrorLog("webp_direct_decode_stream");
    }
    setWebpBitmapOptions(bitmap, opts);
    setPaddingDefaultValues(outPadding);
  } else {
    bitmap = originalDecodeStream(inputStream, outPadding, opts);
    if (bitmap == null) {
      sendWebpErrorLog("webp_direct_decode_stream_failed_on_no_webp");
    }
  }
  return bitmap;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:WebpBitmapFactoryImpl.java

示例12: getImageSize

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * obtain the image's width and height
 *
 * @param imagePath the path of image
 */
public static int[] getImageSize(String imagePath) {
    int[] res = new int[2];

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inSampleSize = 1;
    BitmapFactory.decodeFile(imagePath, options);

    res[0] = options.outWidth;
    res[1] = options.outHeight;

    return res;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:19,代碼來源:BmpUtil.java

示例13: compressDisplay

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * @param width  must > 0
 * @param height must > 0
 */
private Bitmap compressDisplay(String imagePath, int width, int height) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imagePath, options);

    int outH = options.outHeight;
    int outW = options.outWidth;
    int inSampleSize = 1;

    if (outH > height || outW > width) {
        int halfH = outH / 2;
        int halfW = outW / 2;
        while ((halfH / inSampleSize) > height && (halfW / inSampleSize) > width) {
            inSampleSize *= 2;
        }
    }

    options.inSampleSize = inSampleSize;

    options.inJustDecodeBounds = false;

    int heightRatio = (int) Math.ceil(options.outHeight / (float) height);
    int widthRatio = (int) Math.ceil(options.outWidth / (float) width);

    if (heightRatio > 1 || widthRatio > 1) {
        if (heightRatio > widthRatio) {
            options.inSampleSize = heightRatio;
        } else {
            options.inSampleSize = widthRatio;
        }
    }
    options.inJustDecodeBounds = false;

    return BitmapFactory.decodeFile(imagePath, options);
}
 
開發者ID:devzwy,項目名稱:NeiHanDuanZiTV,代碼行數:40,代碼來源:ImageCompressor.java

示例14: loadTexture

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static int loadTexture(final Context context, final int resourceId)
{
	final int[] textureHandle = new int[1];
	
	GLES20.glGenTextures(1, textureHandle, 0);
	
	if (textureHandle[0] != 0)
	{
		final BitmapFactory.Options options = new BitmapFactory.Options();
		options.inScaled = false;	// No pre-scaling

		// Read in the resource
		final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
					
		// Bind to the texture in OpenGL
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		
		// Set filtering
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
		
		// Load the bitmap into the bound texture.
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		
		// Recycle the bitmap, since its data has been loaded into OpenGL.
		bitmap.recycle();						
	}
	
	if (textureHandle[0] == 0)
	{
		throw new RuntimeException("Error loading texture.");
	}
	
	return textureHandle[0];
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:36,代碼來源:TextureHelper.java

示例15: decodeBitmapFromPath

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap decodeBitmapFromPath(String srcPath, int reqWidth, int reqHeight) {
    // First decode with <code>inJustDecodeBounds = true</code> to check dimensions.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(srcPath, options);

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

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(srcPath, options);
}
 
開發者ID:jiajieshen,項目名稱:AndroidDevSamples,代碼行數:14,代碼來源:BitmapUtil.java


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