Here are the examples of the java api class android.graphics.BitmapFactory.Options taken from open source projects.
1. BaseImageDecoder#prepareDecodingOptions()
Project: WliveTV
File: BaseImageDecoder.java
File: BaseImageDecoder.java
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) { ImageScaleType scaleType = decodingInfo.getImageScaleType(); int scale; if (scaleType == ImageScaleType.NONE) { scale = 1; } else if (scaleType == ImageScaleType.NONE_SAFE) { scale = ImageSizeUtils.computeMinImageSampleSize(imageSize); } else { ImageSize targetSize = decodingInfo.getTargetSize(); boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2; scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2); } if (scale > 1 && loggingEnabled) { L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey()); } Options decodingOptions = decodingInfo.getDecodingOptions(); decodingOptions.inSampleSize = scale; return decodingOptions; }
2. BaseImageDecoder#defineImageSizeAndRotation()
Project: WliveTV
File: BaseImageDecoder.java
File: BaseImageDecoder.java
protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(imageStream, null, options); ExifInfo exif; String imageUri = decodingInfo.getImageUri(); if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) { exif = defineExifOrientation(imageUri); } else { exif = new ExifInfo(); } return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif); }
3. ImageUtils#getSize()
Project: Gitskarios
File: ImageUtils.java
File: ImageUtils.java
/** * Get size of image * * @return size */ public static Point getSize(final String imagePath) { final Options options = new Options(); options.inJustDecodeBounds = true; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); return new Point(options.outWidth, options.outHeight); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) { try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } } }
4. ImageUtils#getBitmap()
Project: Gitskarios
File: ImageUtils.java
File: ImageUtils.java
/** * Get a bitmap from the image path * * @return bitmap or null if read fails */ public static Bitmap getBitmap(final String imagePath, int sampleSize) { final Options options = new Options(); options.inDither = false; options.inSampleSize = sampleSize; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); return BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) { try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } } }
5. ImageUtils#getSize()
Project: gh4a
File: ImageUtils.java
File: ImageUtils.java
/** * Get size of image * * @param imagePath * @return size */ public static Point getSize(final String imagePath) { final Options options = new Options(); options.inJustDecodeBounds = true; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); return new Point(options.outWidth, options.outHeight); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } }
6. ImageUtils#getBitmap()
Project: gh4a
File: ImageUtils.java
File: ImageUtils.java
/** * Get a bitmap from the image path * * @param imagePath * @param sampleSize * @return bitmap or null if read fails */ public static Bitmap getBitmap(final String imagePath, int sampleSize) { final Options options = new Options(); options.inDither = false; options.inSampleSize = sampleSize; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); return BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } }
7. ImageLoaderUtil#getOption()
Project: Android-ZBLibrary
File: ImageLoaderUtil.java
File: ImageLoaderUtil.java
/**???? * @param cornerRadiusSize * @param defaultImageResId * @return */ @SuppressWarnings("deprecation") private static DisplayImageOptions getOption(int cornerRadiusSize, int defaultImageResId) { Options options0 = new Options(); options0.inPreferredConfig = Bitmap.Config.RGB_565; DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder(); if (defaultImageResId > 0) { try { builder.showImageForEmptyUri(defaultImageResId).showImageOnLoading(defaultImageResId).showImageOnFail(defaultImageResId); } catch (Exception e) { Log.e(TAG, "getOption try {builder.showImageForEmptyUri(defaultImageResId) ..." + " >> } catch (Exception e) { \n" + e.getMessage()); } } if (cornerRadiusSize > 0) { builder.displayer(new RoundedBitmapDisplayer(cornerRadiusSize)); } return builder.cacheInMemory(true).cacheOnDisc(true).decodingOptions(options0).build(); }
8. ImageLoaderUtil#getOption()
Project: Android-ZBLibrary
File: ImageLoaderUtil.java
File: ImageLoaderUtil.java
/**???? * @param cornerRadiusSize * @param defaultImageResId * @return */ @SuppressWarnings("deprecation") private static DisplayImageOptions getOption(int cornerRadiusSize, int defaultImageResId) { Options options0 = new Options(); options0.inPreferredConfig = Bitmap.Config.RGB_565; DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder(); if (defaultImageResId > 0) { try { builder.showImageForEmptyUri(defaultImageResId).showImageOnLoading(defaultImageResId).showImageOnFail(defaultImageResId); } catch (Exception e) { Log.e(TAG, "getOption try {builder.showImageForEmptyUri(defaultImageResId) ..." + " >> } catch (Exception e) { \n" + e.getMessage()); } } if (cornerRadiusSize > 0) { builder.displayer(new RoundedBitmapDisplayer(cornerRadiusSize)); } return builder.cacheInMemory(true).cacheOnDisc(true).decodingOptions(options0).build(); }
9. BaseImageDecoder#prepareDecodingOptions()
Project: Android-Universal-Image-Loader
File: BaseImageDecoder.java
File: BaseImageDecoder.java
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) { ImageScaleType scaleType = decodingInfo.getImageScaleType(); int scale; if (scaleType == ImageScaleType.NONE) { scale = 1; } else if (scaleType == ImageScaleType.NONE_SAFE) { scale = ImageSizeUtils.computeMinImageSampleSize(imageSize); } else { ImageSize targetSize = decodingInfo.getTargetSize(); boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2; scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2); } if (scale > 1 && loggingEnabled) { L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey()); } Options decodingOptions = decodingInfo.getDecodingOptions(); decodingOptions.inSampleSize = scale; return decodingOptions; }
10. BaseImageDecoder#defineImageSizeAndRotation()
Project: Android-Universal-Image-Loader
File: BaseImageDecoder.java
File: BaseImageDecoder.java
protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(imageStream, null, options); ExifInfo exif; String imageUri = decodingInfo.getImageUri(); if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) { exif = defineExifOrientation(imageUri); } else { exif = new ExifInfo(); } return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif); }
11. BaseImageDecoder#prepareDecodingOptions()
Project: android-open-project-demo
File: BaseImageDecoder.java
File: BaseImageDecoder.java
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) { ImageScaleType scaleType = decodingInfo.getImageScaleType(); int scale; if (scaleType == ImageScaleType.NONE) { scale = 1; } else if (scaleType == ImageScaleType.NONE_SAFE) { scale = ImageSizeUtils.computeMinImageSampleSize(imageSize); } else { ImageSize targetSize = decodingInfo.getTargetSize(); boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2; scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2); } if (scale > 1 && loggingEnabled) { L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey()); } Options decodingOptions = decodingInfo.getDecodingOptions(); decodingOptions.inSampleSize = scale; return decodingOptions; }
12. BaseImageDecoder#defineImageSizeAndRotation()
Project: android-open-project-demo
File: BaseImageDecoder.java
File: BaseImageDecoder.java
protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(imageStream, null, options); ExifInfo exif; String imageUri = decodingInfo.getImageUri(); if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) { exif = defineExifOrientation(imageUri); } else { exif = new ExifInfo(); } return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif); }
13. BitmapUtils#getSampledBitmap()
Project: android-open-project-demo
File: BitmapUtils.java
File: BitmapUtils.java
public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { if (width > height) { //Math.round((float)height / (float)reqHeight); inSampleSize = (int) FloatMath.floor(((float) height / reqHeight) + 0.5f); } else { //Math.round((float)width / (float)reqWidth); inSampleSize = (int) FloatMath.floor(((float) width / reqWidth) + 0.5f); } } options.inSampleSize = inSampleSize; options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options); }
14. GameView#getResBitmap()
Project: android-maven-plugin
File: GameView.java
File: GameView.java
private Bitmap getResBitmap(int bmpResId) { Options opts = new Options(); opts.inDither = false; Resources res = getResources(); Bitmap bmp = BitmapFactory.decodeResource(res, bmpResId, opts); if (bmp == null && isInEditMode()) { // BitmapFactory.decodeResource doesn't work from the rendering // library in Eclipse's Graphical Layout Editor. Use this workaround instead. Drawable d = res.getDrawable(bmpResId); int w = d.getIntrinsicWidth(); int h = d.getIntrinsicHeight(); bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas c = new Canvas(bmp); d.setBounds(0, 0, w - 1, h - 1); d.draw(c); } return bmp; }
15. DefaultImageDecoder#decodeFromHelper()
Project: Sketch
File: DefaultImageDecoder.java
File: DefaultImageDecoder.java
public static DecodeResult decodeFromHelper(LoadRequest loadRequest, DecodeHelper decodeHelper, String logName) { Options boundsOptions = new Options(); Options decodeOptions = new Options(); // ????????????? boundsOptions.inJustDecodeBounds = true; decodeHelper.decode(boundsOptions); // ?????? String mimeType = boundsOptions.outMimeType; ImageFormat imageFormat = ImageFormat.valueOfMimeType(mimeType); // ???????????? if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1 && loadRequest.getOptions().isInPreferQualityOverSpeed()) { decodeOptions.inPreferQualityOverSpeed = true; } // setup bitmap config if (loadRequest.getOptions().getBitmapConfig() != null) { // by user decodeOptions.inPreferredConfig = loadRequest.getOptions().getBitmapConfig(); } else if (imageFormat != null) { // best bitmap config by MimeType decodeOptions.inPreferredConfig = imageFormat.getConfig(loadRequest.getOptions().isLowQualityImage()); } // decode gif image if (imageFormat != null && imageFormat == ImageFormat.GIF && loadRequest.getOptions().isDecodeGifImage()) { try { return new DecodeResult(mimeType, decodeHelper.getGifDrawable()); } catch (Throwable e) { e.printStackTrace(); ErrorCallback errorCallback = loadRequest.getSketch().getConfiguration().getErrorCallback(); if (errorCallback != null) { errorCallback.onDecodeGifImageFailed(e, loadRequest, boundsOptions); } } } // decode normal image Bitmap bitmap = null; Point originalSize = new Point(boundsOptions.outWidth, boundsOptions.outHeight); if (boundsOptions.outWidth != 1 && boundsOptions.outHeight != 1) { // calculate inSampleSize MaxSize maxSize = loadRequest.getOptions().getMaxSize(); if (maxSize != null) { ImageSizeCalculator imageSizeCalculator = loadRequest.getSketch().getConfiguration().getImageSizeCalculator(); decodeOptions.inSampleSize = imageSizeCalculator.calculateInSampleSize(boundsOptions.outWidth, boundsOptions.outHeight, maxSize.getWidth(), maxSize.getHeight()); } // Decoding and exclude the width or height of 1 pixel image try { bitmap = decodeHelper.decode(decodeOptions); } catch (Throwable error) { error.printStackTrace(); ErrorCallback errorCallback = loadRequest.getSketch().getConfiguration().getErrorCallback(); if (errorCallback != null) { boundsOptions.inSampleSize = decodeOptions.inSampleSize; errorCallback.onDecodeNormalImageFailed(error, loadRequest, boundsOptions); } } if (bitmap != null && (bitmap.getWidth() == 1 || bitmap.getHeight() == 1)) { if (Sketch.isDebugMode()) { Log.w(Sketch.TAG, SketchUtils.concat(logName, " - ", "bitmap width or height is 1px", " - ", "ImageSize: ", originalSize.x, "x", originalSize.y, " - ", "BitmapSize: ", bitmap.getWidth(), "x", bitmap.getHeight(), " - ", loadRequest.getAttrs().getId())); } bitmap.recycle(); bitmap = null; } } else { if (Sketch.isDebugMode()) { Log.e(Sketch.TAG, SketchUtils.concat(logName, " - ", "image width or height is 1px", " - ", "ImageSize: ", originalSize.x, "x", originalSize.y, " - ", loadRequest.getAttrs().getId())); } } // Results the callback if (bitmap != null && !bitmap.isRecycled()) { decodeHelper.onDecodeSuccess(bitmap, originalSize, decodeOptions.inSampleSize); } else { bitmap = null; decodeHelper.onDecodeFailed(); } return bitmap != null ? new DecodeResult(mimeType, bitmap) : null; }
16. BitmapUtils#decodeSampledBitmapFromFile()
Project: MyRepository-master
File: BitmapUtils.java
File: BitmapUtils.java
/** * Decodes a bitmap from a file containing it minimizing the memory use, known that the bitmap * will be drawn in a surface of reqWidth x reqHeight * * @param srcPath Absolute path to the file containing the image. * @param reqWidth Width of the surface where the Bitmap will be drawn on, in pixels. * @param reqHeight Height of the surface where the Bitmap will be drawn on, in pixels. * @return */ public static Bitmap decodeSampledBitmapFromFile(String srcPath, int reqWidth, int reqHeight) { // set desired options that will affect the size of the bitmap final Options options = new Options(); options.inScaled = true; options.inPurgeable = true; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { options.inPreferQualityOverSpeed = false; } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { options.inMutable = false; } // make a false load of the bitmap to get its dimensions options.inJustDecodeBounds = true; BitmapFactory.decodeFile(srcPath, options); // calculate factor to subsample the bitmap options.inSampleSize = calculateSampleFactor(options, reqWidth, reqHeight); // decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(srcPath, options); }
17. BordersPanel#onCreate()
Project: mobile-android
File: BordersPanel.java
File: BordersPanel.java
@SuppressWarnings("deprecation") @Override public void onCreate(Bitmap bitmap) { super.onCreate(bitmap); mImageManager = new AsyncImageManager(1); mThumbnailOptions = new Options(); mThumbnailOptions.inPreferredConfig = Config.RGB_565; mPluginService = getContext().getService(PluginService.class); mCacheService = getContext().getService(ImageCacheService.class); mPreferenceService = getContext().getService(PreferenceService.class); if (mPluginType == FeatherIntent.PluginType.TYPE_FILTER) mExternalPacksEnabled = Constants.getValueFromIntent(Constants.EXTRA_EFFECTS_ENABLE_EXTERNAL_PACKS, true); else mExternalPacksEnabled = Constants.getValueFromIntent(Constants.EXTRA_FRAMES_ENABLE_EXTERNAL_PACKS, true); mViewFlipper = (ViewFlipper) getOptionView().findViewById(R.id.flipper); mHList = (HorizontalVariableListView) getOptionView().findViewById(R.id.list); mHList.setOverScrollMode(View.OVER_SCROLL_ALWAYS); mPreview = BitmapUtils.copy(mBitmap, Bitmap.Config.ARGB_8888); // ImageView Switcher setup mImageSwitcher = (ImageSwitcher) getContentView().findViewById(R.id.switcher); initContentImage(mImageSwitcher); // Horizontal list setup mHList.setOnScrollListener(this); View content = getOptionView().findViewById(R.id.background); content.setBackgroundDrawable(RepeatableHorizontalDrawable.createFromView(content)); try { updateArrowBitmap = BitmapFactory.decodeResource(getContext().getBaseContext().getResources(), R.drawable.feather_update_arrow); } catch (Throwable t) { } mEnableEffectAnimation = Constants.ANDROID_SDK > android.os.Build.VERSION_CODES.GINGERBREAD && SystemUtils.getCpuMhz() > 800; // mSelectedPosition = 0; }
18. AndroidGraphics#newImage()
Project: LPOO
File: AndroidGraphics.java
File: AndroidGraphics.java
@Override public Image newImage(String fileName, ImageFormat format) { Config config = null; if (format == ImageFormat.RGB565) config = Config.RGB_565; else if (format == ImageFormat.ARGB4444) config = Config.ARGB_4444; else config = Config.ARGB_8888; Options options = new Options(); options.inPreferredConfig = config; InputStream in = null; Bitmap bitmap = null; try { in = assets.open(fileName); bitmap = BitmapFactory.decodeStream(in, null, options); if (bitmap == null) throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } catch (IOException e) { throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } if (bitmap.getConfig() == Config.RGB_565) format = ImageFormat.RGB565; else if (bitmap.getConfig() == Config.ARGB_4444) format = ImageFormat.ARGB4444; else format = ImageFormat.ARGB8888; return new AndroidImage(bitmap, format); }
19. AndroidGraphics#newImage()
Project: LPOO
File: AndroidGraphics.java
File: AndroidGraphics.java
@Override public Image newImage(String fileName, ImageFormat format) { Config config = null; if (format == ImageFormat.RGB565) config = Config.RGB_565; else if (format == ImageFormat.ARGB4444) config = Config.ARGB_4444; else config = Config.ARGB_8888; Options options = new Options(); options.inPreferredConfig = config; InputStream in = null; Bitmap bitmap = null; try { in = assets.open(fileName); bitmap = BitmapFactory.decodeStream(in, null, options); if (bitmap == null) throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } catch (IOException e) { throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } if (bitmap.getConfig() == Config.RGB_565) format = ImageFormat.RGB565; else if (bitmap.getConfig() == Config.ARGB_4444) format = ImageFormat.ARGB4444; else format = ImageFormat.ARGB8888; return new AndroidImage(bitmap, format); }
20. AsyncBitmapTexture#standardBitmapFactoryOptions()
Project: GearVRf
File: AsyncBitmapTexture.java
File: AsyncBitmapTexture.java
private static Options standardBitmapFactoryOptions() { Options options = new Options(); options.inPurgeable = false; options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inTempStorage = bufferBin.get(); if (options.inTempStorage == null) { options.inTempStorage = new byte[DECODE_BUFFER_SIZE]; } return options; }
21. ImageHelper#resizeBitmap()
Project: fanfouapp-opensource
File: ImageHelper.java
File: ImageHelper.java
public static Bitmap resizeBitmap(final String filePath, final int width, final int height) { Bitmap bitmap = null; final Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); double sampleSize = 0; final Boolean scaleByHeight = Math.abs(options.outHeight - height) >= Math.abs(options.outWidth - width); if ((options.outHeight * options.outWidth * 2) >= 16384) { sampleSize = scaleByHeight ? options.outHeight / height : options.outWidth / width; sampleSize = (int) Math.pow(2d, Math.floor(Math.log(sampleSize) / Math.log(2d))); } options.inJustDecodeBounds = false; options.inTempStorage = new byte[128]; while (true) { try { options.inSampleSize = (int) sampleSize; bitmap = BitmapFactory.decodeFile(filePath, options); break; } catch (final Exception ex) { sampleSize = sampleSize * 2; } } return bitmap; }
22. AbstractImageData#getImageSize()
Project: document-viewer
File: AbstractImageData.java
File: AbstractImageData.java
protected Options getImageSize(char[] ch, int start, int length) { final Options opts = new Options(); opts.inJustDecodeBounds = true; final Base64InputStream stream = new Base64InputStream(new AsciiCharInputStream(ch, start, length), Base64.DEFAULT); BitmapFactory.decodeStream(stream, null, opts); try { stream.close(); } catch (final IOException ex) { } return opts; }
23. AbstractImageData#getImageSize()
Project: document-viewer
File: AbstractImageData.java
File: AbstractImageData.java
protected Options getImageSize(final String encoded) { final Options opts = new Options(); opts.inJustDecodeBounds = true; final Base64InputStream stream = new Base64InputStream(new AsciiCharStringInputStream(encoded), Base64.DEFAULT); BitmapFactory.decodeStream(stream, null, opts); try { stream.close(); } catch (final IOException ex) { } return opts; }
24. AbstractImageData#getImageRect()
Project: document-viewer
File: AbstractImageData.java
File: AbstractImageData.java
@Override public final RectF getImageRect(final boolean inline) { float w = 0, h = 0; final Options opts = getImageSize(); if (opts != null) { final int origWidth = opts.outWidth; final int origHeight = opts.outHeight; if (origWidth <= FB2Page.PAGE_WIDTH - 2 * FB2Page.MARGIN_X && origHeight <= FB2Page.PAGE_HEIGHT - 2 * FB2Page.MARGIN_Y && inline) { w = origWidth; h = origHeight; } else { if (origWidth > FB2Page.PAGE_WIDTH - 2 * FB2Page.MARGIN_X || !inline) { w = FB2Page.PAGE_WIDTH - 2 * FB2Page.MARGIN_X; h = origHeight * w / origWidth; } else { w = origWidth; h = origHeight; } if (h > FB2Page.PAGE_HEIGHT - 2 * FB2Page.MARGIN_X) { w = w * (FB2Page.PAGE_HEIGHT - 2 * FB2Page.MARGIN_Y) / h; h = FB2Page.PAGE_HEIGHT - 2 * FB2Page.MARGIN_X; } } } return new RectF(0f, 0f, w, h); }
25. BitmapAjaxCallback#getResizedImage()
Project: BeeFramework_Android
File: BitmapAjaxCallback.java
File: BitmapAjaxCallback.java
/** * Utility method for downsampling images. * * @param path the file path * @param data if file path is null, provide the image data directly * @param target the target dimension * @param width use width as target, otherwise use the higher value of height or width * @param round corner radius * @param rotate auto rotate with exif data * @return the resized image */ public static Bitmap getResizedImage(String path, byte[] data, int target, boolean width, int round, boolean rotate) { if (path == null && data == null) return null; Options options = null; if (target > 0) { Options info = new Options(); info.inJustDecodeBounds = true; decode(path, data, info, rotate); int dim = info.outWidth; if (!width) dim = Math.max(dim, info.outHeight); int ssize = sampleSize(dim, target); options = new Options(); options.inSampleSize = ssize; } Bitmap bm = null; try { bm = decode(path, data, options, rotate); } catch (OutOfMemoryError e) { clearCache(); AQUtility.report(e); } if (round > 0) { bm = getRoundedCornerBitmap(bm, round); } return bm; }
26. BitmapUtils#getBitmapSize()
Project: android-open-project-demo
File: BitmapUtils.java
File: BitmapUtils.java
public static BitmapSize getBitmapSize(String filePath) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); return new BitmapSize(options.outWidth, options.outHeight); }
27. BitmapUtils#decodeSampledBitmapFromFile()
Project: android
File: BitmapUtils.java
File: BitmapUtils.java
/** * Decodes a bitmap from a file containing it minimizing the memory use, known that the bitmap * will be drawn in a surface of reqWidth x reqHeight * * @param srcPath Absolute path to the file containing the image. * @param reqWidth Width of the surface where the Bitmap will be drawn on, in pixels. * @param reqHeight Height of the surface where the Bitmap will be drawn on, in pixels. * @return */ public static Bitmap decodeSampledBitmapFromFile(String srcPath, int reqWidth, int reqHeight) { // set desired options that will affect the size of the bitmap final Options options = new Options(); options.inScaled = true; options.inPurgeable = true; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { options.inPreferQualityOverSpeed = false; } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { options.inMutable = false; } // make a false load of the bitmap to get its dimensions options.inJustDecodeBounds = true; BitmapFactory.decodeFile(srcPath, options); // calculate factor to subsample the bitmap options.inSampleSize = calculateSampleFactor(options, reqWidth, reqHeight); // decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(srcPath, options); }
28. AcApp#decodeBitmap()
Project: AcFun-Area63
File: AcApp.java
File: AcApp.java
public static Bitmap decodeBitmap(String imagePath, Bitmap.Config config) { Options opts = new Options(); opts.inPreferredConfig = config; Bitmap bitmap = BitmapFactory.decodeFile(imagePath, opts); return bitmap; }