use of android.graphics.BitmapFactory.Options in project Android-Universal-Image-Loader by nostra13.
the class BaseImageDecoder method decode.
/**
* Decodes image from URI into {@link Bitmap}. Image is scaled close to incoming {@linkplain ImageSize target size}
* during decoding (depend on incoming parameters).
*
* @param decodingInfo Needed data for decoding image
* @return Decoded bitmap
* @throws IOException if some I/O exception occurs during image reading
* @throws UnsupportedOperationException if image URI has unsupported scheme(protocol)
*/
@Override
public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
Bitmap decodedBitmap;
ImageFileInfo imageInfo;
InputStream imageStream = getImageStream(decodingInfo);
if (imageStream == null) {
L.e(ERROR_NO_IMAGE_STREAM, decodingInfo.getImageKey());
return null;
}
try {
imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
imageStream = resetStream(imageStream, decodingInfo);
Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo);
decodedBitmap = BitmapFactory.decodeStream(imageStream, null, decodingOptions);
} finally {
IoUtils.closeSilently(imageStream);
}
if (decodedBitmap == null) {
L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
} else {
decodedBitmap = considerExactScaleAndOrientatiton(decodedBitmap, decodingInfo, imageInfo.exif.rotation, imageInfo.exif.flipHorizontal);
}
return decodedBitmap;
}
use of android.graphics.BitmapFactory.Options in project Android-Universal-Image-Loader by nostra13.
the class BaseImageDecoder method prepareDecodingOptions.
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;
}
use of android.graphics.BitmapFactory.Options in project android by owncloud.
the class BitmapUtils method decodeSampledBitmapFromFile.
/**
* 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);
}
use of android.graphics.BitmapFactory.Options in project PocketHub by pockethub.
the class ImageUtils method getSize.
/**
* Get size of image
*
* @param image
* @return size
*/
public static Point getSize(final byte[] image) {
final Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(image, 0, image.length, options);
return new Point(options.outWidth, options.outHeight);
}
use of android.graphics.BitmapFactory.Options in project PocketHub by pockethub.
the class ImageUtils method getBitmap.
/**
* 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);
}
}
}
}
Aggregations