/**获取配置 * @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(); }
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType, ImageDownloader downloader, DisplayImageOptions displayOptions) { this.imageKey = imageKey; this.imageUri = imageUri; this.originalImageUri = originalImageUri; this.targetSize = targetSize; this.imageScaleType = displayOptions.getImageScaleType(); this.viewScaleType = viewScaleType; this.downloader = downloader; this.extraForDownloader = displayOptions.getExtraForDownloader(); considerExifParams = displayOptions.isConsiderExifParams(); decodingOptions = new Options(); copyOptions(displayOptions.getDecodingOptions(), decodingOptions); }
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; }
public static Bitmap getScaleBitmap(Context context, String imagePath, int maxWidth) { try { Options bitmapOptions = new Options(); bitmapOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(imagePath, bitmapOptions); int imageWidth = bitmapOptions.outWidth; if (maxWidth == 0) { maxWidth = DevUtils.getScreenWidth(context); } else if (maxWidth < 0) { maxWidth = imageWidth; } if (imageWidth < maxWidth) { maxWidth = imageWidth; } Bitmap bitmap = createScaleBitmapByWidthIfNeed(imagePath, maxWidth); return bitmap; } catch (OutOfMemoryError e) { Log.e("BitmapUtils", "compressBitmap", e); return null; } }
/** * 从系统的asset中读取一张图片 . <br> * @author liulongzhenhai 2012-8-1 下午5:21:12 <br> * @param context 上下文 * @param fileName 文件相对路劲 * @param density Options.inDensity的设置,在一些情况下,需要制定.否则,会变形 * @return 返回图片 */ public static Bitmap getImageFromAssetFile(final Context context, final String fileName, final int density) { if (TextUtils.isEmpty(fileName)) { return null; } Bitmap image = null; try { final AssetManager am = context.getAssets(); final InputStream is = am.open(fileName); final Options o = new Options(); o.inDensity = density; image = BitmapFactory.decodeStream(is, null, o); is.close(); } catch (final Exception e) { } return image; }
private void copyOptions(Options srcOptions, Options destOptions) { destOptions.inDensity = srcOptions.inDensity; destOptions.inDither = srcOptions.inDither; destOptions.inInputShareable = srcOptions.inInputShareable; destOptions.inJustDecodeBounds = srcOptions.inJustDecodeBounds; destOptions.inPreferredConfig = srcOptions.inPreferredConfig; destOptions.inPurgeable = srcOptions.inPurgeable; destOptions.inSampleSize = srcOptions.inSampleSize; destOptions.inScaled = srcOptions.inScaled; destOptions.inScreenDensity = srcOptions.inScreenDensity; destOptions.inTargetDensity = srcOptions.inTargetDensity; destOptions.inTempStorage = srcOptions.inTempStorage; if (VERSION.SDK_INT >= 10) { copyOptions10(srcOptions, destOptions); } if (VERSION.SDK_INT >= 11) { copyOptions11(srcOptions, destOptions); } }
/** * @description:解析Bitmap的公用方法.注意各个方法的参数必须要有options * @author:hui-ye * @param path * @param data * @param context * @param uri * @param options * @return: */ public static Bitmap decode(String path, byte[] data, Context context, Uri uri, Options options) throws Exception { Bitmap bitmap = null; if (path != null) { bitmap = BitmapFactory.decodeFile(path, options); } else if (data != null) { BitmapFactory.decodeByteArray(data, 0, data.length, options); } else if (uri != null) { // uri不为空的时候context也不要为空.:ContentResolver;Uri内容解析器 ContentResolver resolver = context.getContentResolver(); InputStream is; is = resolver.openInputStream(uri); bitmap = BitmapFactory.decodeStream(is, null, options); } System.gc(); return bitmap; }
public static Options getBitmapOptions(byte[] bArr) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options); int ceil = (int) Math.ceil((double) (options.outWidth / UMImage.MAX_WIDTH)); int ceil2 = (int) Math.ceil((double) (options.outHeight / UMImage.MAX_HEIGHT)); if (ceil2 <= 1 || ceil <= 1) { if (ceil2 > 2) { options.inSampleSize = ceil2; } else if (ceil > 2) { options.inSampleSize = ceil; } } else if (ceil2 > ceil) { options.inSampleSize = ceil2; } else { options.inSampleSize = ceil; } options.inJustDecodeBounds = false; return options; }
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) { int scale; ImageScaleType scaleType = decodingInfo.getImageScaleType(); if (scaleType == ImageScaleType.NONE) { scale = 1; } else if (scaleType == ImageScaleType.NONE_SAFE) { scale = ImageSizeUtils.computeMinImageSampleSize(imageSize); } else { boolean powerOf2; ImageSize targetSize = decodingInfo.getTargetSize(); if (scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2) { powerOf2 = true; } else { powerOf2 = false; } scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2); } if (scale > 1 && this.loggingEnabled) { L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), Integer.valueOf(scale), decodingInfo.getImageKey()); } Options decodingOptions = decodingInfo.getDecodingOptions(); decodingOptions.inSampleSize = scale; return decodingOptions; }
public Bitmap decodeAbtoBm(byte[] b, int actualSize) { System.gc(); Runtime.getRuntime().gc(); Options oo = new Options(); oo.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(b, 0, b.length, oo); int scale = 1; while ((oo.outWidth / scale) / 2 >= actualSize && (oo.outHeight / scale) / 2 >= actualSize) { scale *= 2; } Options o2 = new Options(); o2.inSampleSize = scale; o2.inPurgeable = true; o2.inInputShareable = true; Bitmap bm = BitmapFactory.decodeByteArray(b, 0, b.length, o2); System.gc(); Runtime.getRuntime().gc(); return bm; }
public static Bitmap getBitmapByPath(String filename) { if (!checkFileIsEnabledPath(filename)) { return null; } Options newOpts = new Options(); newOpts.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(filename, newOpts); int w = newOpts.outWidth; int h = newOpts.outHeight; if (bitmap != null) { bitmap.recycle(); } int be = 1; if (w > h && ((float) w) > 300.0f) { be = (int) (((float) newOpts.outWidth) / 300.0f); } else if (w < h && ((float) h) > 400.0f) { be = (int) (((float) newOpts.outHeight) / 400.0f); } if (be <= 0) { be = 1; } Options newOpts2 = new Options(); newOpts2.inSampleSize = be; newOpts2.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filename, newOpts2); }
private static int computeInitialSampleSize(Options options, int minSideLength, int maxNumOfPixels) { double w = (double) options.outWidth; double h = (double) options.outHeight; int lowerBound = maxNumOfPixels == -1 ? 1 : (int) Math.ceil(Math.sqrt((w * h) / ((double) maxNumOfPixels))); int upperBound = minSideLength == -1 ? 128 : (int) Math.min(Math.floor(w / ((double) minSideLength)), Math.floor(h / ((double) minSideLength))); if (upperBound < lowerBound) { return lowerBound; } if (maxNumOfPixels == -1 && minSideLength == -1) { return 1; } if (minSideLength != -1) { return upperBound; } return lowerBound; }
private static final boolean b(String str, int i, int i2) { if (TextUtils.isEmpty(str)) { return false; } Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(str, options); int i3 = options.outWidth; int i4 = options.outHeight; if (options.mCancel || options.outWidth == -1 || options.outHeight == -1) { return false; } int i5 = i3 > i4 ? i3 : i4; if (i3 >= i4) { i3 = i4; } f.b("AsynScaleCompressImage", "longSide=" + i5 + "shortSide=" + i3); options.inPreferredConfig = Config.RGB_565; if (i5 > i2 || i3 > i) { return true; } return false; }
private Bitmap a(String str) throws IOException { int i = 1; Options options = new Options(); options.inJustDecodeBounds = true; Uri parse = Uri.parse(str); InputStream openInputStream = getContentResolver().openInputStream(parse); if (openInputStream == null) { return null; } BitmapFactory.decodeStream(openInputStream, null, options); openInputStream.close(); int i2 = options.outWidth; int i3 = options.outHeight; while (i2 * i3 > 4194304) { i2 /= 2; i3 /= 2; i *= 2; } options.inJustDecodeBounds = false; options.inSampleSize = i; return BitmapFactory.decodeStream(getContentResolver().openInputStream(parse), null, options); }
public static IconRequest build(Context context, String iconHash) { if (iconHash == null) { return null; } try { int iconId = CommonUtils.getAppIconResourceId(context); Fabric.getLogger().d(Fabric.TAG, "App icon resource ID is " + iconId); Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), iconId, options); return new IconRequest(iconHash, iconId, options.outWidth, options.outHeight); } catch (Exception e) { Fabric.getLogger().e(Fabric.TAG, "Failed to load icon", e); return null; } }
public ImageDecodingInfo(String imageKey, String imageUri, ImageSize targetSize, ViewScaleType viewScaleType, ImageDownloader downloader, DisplayImageOptions displayOptions) { this.imageKey = imageKey; this.imageUri = imageUri; this.targetSize = targetSize; this.imageScaleType = displayOptions.getImageScaleType(); this.viewScaleType = viewScaleType; this.downloader = downloader; this.extraForDownloader = displayOptions.getExtraForDownloader(); considerExifParams = displayOptions.isConsiderExifParams(); decodingOptions = new Options(); copyOptions(displayOptions.getDecodingOptions(), decodingOptions); }
private Bitmap loadBitmap(Uri uri, Options o) throws FileNotFoundException { if (uri == null || this.mContext == null) { throw new IllegalArgumentException("bad argument to loadBitmap"); } InputStream is = null; try { is = this.mContext.getContentResolver().openInputStream(uri); Bitmap decodeStream = BitmapFactory.decodeStream(is, null, o); if (is != null) { try { is.close(); } catch (IOException t) { Log.w(LOG_TAG, "close fail ", t); } } return decodeStream; } catch (Throwable th) { if (is != null) { try { is.close(); } catch (IOException t2) { Log.w(LOG_TAG, "close fail ", t2); } } } }
/** * 计算缩放比例 * @param options * @param reqWidth * 目标宽 * @param reqHeight * 目标高 * @return */ private int calculateInSampleSize(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 inSampleSize; } if (height > reqHeight || width > reqWidth) { if (width > height) { inSampleSize = Math.round((float) height / (float) reqHeight); } else { inSampleSize = Math.round((float) width / (float) reqWidth); } } Log.d("", "原图尺寸:" + width + "x" + height + ",实际尺寸:" + reqWidth + "x" + reqHeight + ",inSampleSize = " + inSampleSize); return inSampleSize; }
public static Bitmap getImageCompress(final String srcPath) { Options newOpts = new Options(); // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 newOpts.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts);// 此时返回bm为空 newOpts.inJustDecodeBounds = false; int w = newOpts.outWidth; int h = newOpts.outHeight; // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为 float hh = 800f;// 这里设置高度为800f float ww = 480f;// 这里设置宽度为480f // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 int be = 1;// be=1表示不缩放 if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放 be = (int) (newOpts.outWidth / ww); } else if (w < h && h > hh) {// 如果高度高的话根据宽度固定大小缩放 be = (int) (newOpts.outHeight / hh); } if (be <= 0) be = 1; newOpts.inSampleSize = be;// 设置缩放比例 // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 bitmap = BitmapFactory.decodeFile(srcPath, newOpts); return compressImage(bitmap);// 压缩好比例大小后再进行质量压缩 }
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) { 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; }
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) { int scale; ImageScaleType scaleType = decodingInfo.getImageScaleType(); if (scaleType == ImageScaleType.NONE) { scale = 1; } else if (scaleType == ImageScaleType.NONE_SAFE) { scale = ImageSizeUtils.computeMinImageSampleSize(imageSize); } else { boolean powerOf2; ImageSize targetSize = decodingInfo.getTargetSize(); if (scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2) { powerOf2 = true; } else { powerOf2 = false; } scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo .getViewScaleType(), powerOf2); } if (scale > 1 && this.loggingEnabled) { L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), Integer.valueOf (scale), decodingInfo.getImageKey()); } Options decodingOptions = decodingInfo.getDecodingOptions(); decodingOptions.inSampleSize = scale; return decodingOptions; }
public static Bitmap c(String str) { int i = 1; Options options = new Options(); options.inJustDecodeBounds = true; options.inDither = false; options.inPurgeable = true; options.inInputShareable = true; options.inPreferredConfig = Config.RGB_565; BitmapFactory.decodeFile(str, options); if (options.outHeight > 200 || options.outWidth > 200) { i = Math.min(Math.round(((float) options.outHeight) / 200.0f), Math.round(((float) options.outWidth) / 200.0f)); } options.inJustDecodeBounds = false; options.inSampleSize = i; return BitmapFactory.decodeFile(str, options).copy(Config.ARGB_8888, false); }
private static int caculateInSampleSize(Options options, int rqsW, int rqsH) { int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1; if (rqsW == 0 || rqsH == 0) { return 1; } if (height > rqsH || width > rqsW) { int heightRatio = Math.round(((float) height) / ((float) rqsH)); int widthRatio = Math.round(((float) width) / ((float) rqsW)); if (heightRatio < widthRatio) { inSampleSize = heightRatio; } else { inSampleSize = widthRatio; } } return inSampleSize; }
private static int calculateInSampleSize(Options options, int reqWidth, int reqHeight) { int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { int halfHeight = height / 2; int halfWidth = width / 2; inSampleSize = 2; while (true) { if (halfHeight / inSampleSize <= reqHeight && halfWidth / inSampleSize <= reqWidth) { break; } inSampleSize *= 2; } } Helper.showLog("Bitmap Util:", inSampleSize + ""); return inSampleSize; }
/** * Utility function for decoding an image resource. The decoded bitmap will * be optimized for further scaling to the requested destination dimensions * and scaling logic. * * @param res The resources object containing the image data * @param resId The resource id of the image data * @param dstWidth Width of destination area * @param dstHeight Height of destination area * @param scalingLogic Logic to use to avoid image stretching * @return Decoded bitmap */ public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight, ScalingLogic scalingLogic) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight, scalingLogic); Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); return unscaledBitmap; }
private void copyOptions(Options srcOptions, Options destOptions) { destOptions.inDensity = srcOptions.inDensity; destOptions.inDither = srcOptions.inDither; destOptions.inInputShareable = srcOptions.inInputShareable; destOptions.inJustDecodeBounds = srcOptions.inJustDecodeBounds; destOptions.inPreferredConfig = srcOptions.inPreferredConfig; destOptions.inPurgeable = srcOptions.inPurgeable; destOptions.inSampleSize = srcOptions.inSampleSize; destOptions.inScaled = srcOptions.inScaled; destOptions.inScreenDensity = srcOptions.inScreenDensity; destOptions.inTargetDensity = srcOptions.inTargetDensity; destOptions.inTempStorage = srcOptions.inTempStorage; if (Build.VERSION.SDK_INT >= 10) copyOptions10(srcOptions, destOptions); if (Build.VERSION.SDK_INT >= 11) copyOptions11(srcOptions, destOptions); }
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); }
public static Bitmap getBitmapFromUri(Context context, Uri uri, Options options) { Bitmap bitmap = null; InputStream is = null; try { is = context.getContentResolver().openInputStream(uri); bitmap = BitmapFactory.decodeStream(is, null, options); if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } catch (FileNotFoundException e2) { e2.printStackTrace(); if (is != null) { try { is.close(); } catch (IOException e3) { e3.printStackTrace(); } } } catch (Throwable th) { if (is != null) { try { is.close(); } catch (IOException e32) { e32.printStackTrace(); } } } return bitmap; }
public static void saveBitmapFronPath(String srcPath, String picName, String filePath) throws FileNotFoundException { Options options = new Options(); options.inJustDecodeBounds = true; Bitmap temp = BitmapFactory.decodeFile(srcPath, options); options.inJustDecodeBounds = false; int actualWidth = options.outWidth; int actualHeight = options.outHeight; int desiredWidth = actualWidth; int desiredHeight = actualHeight; if (actualWidth > NOMARL_SIZE && actualHeight > NOMARL_SIZE) { if (actualWidth > actualHeight) { desiredWidth = (int) (actualWidth * ((NOMARL_SIZE *1.0) / actualHeight)); desiredHeight = NOMARL_SIZE; } else { desiredHeight = (int) (actualHeight * ((NOMARL_SIZE *1.0)/ actualWidth)); desiredWidth = NOMARL_SIZE; } } options.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight); options.inPurgeable = true;// 同时设置才会有效 options.inInputShareable = true;//。当系统内存不够时候图片自动被回收 temp = BitmapFactory.decodeFile(srcPath, options); Bitmap resizedBitmap = Bitmap.createScaledBitmap(temp, desiredWidth, desiredHeight, true); resizedBitmap = BitmapUtil.getRotationBitmap(srcPath, resizedBitmap); saveBitmap(resizedBitmap, new File(filePath,picName)); if(null != temp){ temp.recycle(); } if(null != resizedBitmap){ resizedBitmap.recycle(); } }
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) { inSampleSize = (int)FloatMath.floor(((float)height / reqHeight)+0.5f); //Math.round((float)height / (float)reqHeight); } else { inSampleSize = (int)FloatMath.floor(((float)width / reqWidth)+0.5f); //Math.round((float)width / (float)reqWidth); } } options.inSampleSize = inSampleSize; options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options); }
public static Bitmap decodeBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inSampleSize = calcInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res, resId, options); }
/** * 压缩收藏表情,最大边压到150 */ public static Bitmap getFaceBitmapFronPath(Context context, String filePath) throws FileNotFoundException { if (null == filePath) { return null; } Options options = new Options(); options.inJustDecodeBounds = true; Bitmap temp = BitmapFactory.decodeFile(filePath, options); options.inJustDecodeBounds = false; int actualWidth = options.outWidth; int actualHeight = options.outHeight; int desiredWidth = actualWidth; int desiredHeight = actualHeight; if (actualWidth > 150 && actualHeight > 150) { if (actualWidth > actualHeight) { desiredWidth = (int) (actualWidth * ((150 *1.0) / actualHeight)); desiredHeight = 150; } else { desiredHeight = (int) (actualHeight * ((150 *1.0)/ actualWidth)); desiredWidth = 150; } } options.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight); temp = BitmapFactory.decodeFile(filePath, options); temp = Bitmap.createScaledBitmap(temp, desiredWidth, desiredHeight, true); return temp; }
private RoundedImageView createImageViewFromFile(int position, String filename) { if (!FileUtils.checkFileIsEnabledPath(filename)) { return null; } Options newOpts = new Options(); newOpts.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(filename, newOpts); int w = newOpts.outWidth; int h = newOpts.outHeight; int be = 1; if (w > h && ((float) w) > 300.0f) { be = (int) (((float) newOpts.outWidth) / 300.0f); } else if (w < h && ((float) h) > 400.0f) { be = (int) (((float) newOpts.outHeight) / 400.0f); } if (be <= 0) { be = 1; } Options newOpts2 = new Options(); newOpts2.inSampleSize = be; newOpts2.inJustDecodeBounds = false; Bitmap bitmap2 = BitmapFactory.decodeFile(filename, newOpts2); RoundedImageView imageView = (RoundedImageView) this.mInflater.inflate(R.layout.videoshot_rounded_item, null, false).findViewById(R.id.riv_imageView); imageView.setTag(Integer.valueOf(position)); imageView.setImageBitmap(bitmap2); if (this.mIVArray != null) { this.mIVArray.add(imageView); return imageView; } this.mIVArray = new ArrayList(); this.mIVArray.add(imageView); return imageView; }