use of android.graphics.BitmapFactory.Options in project GreenDroid by cyrilmottier.
the class AsyncImageView method setInDensity.
/**
* Helper to {@link #setOptions(Options)} that simply sets the inDensity for
* loaded image.
*
* @param inDensity
* @see AsyncImageView#setOptions(Options)
*/
public void setInDensity(int inDensity) {
if (mOptions == null) {
mOptions = new BitmapFactory.Options();
mOptions.inDither = true;
mOptions.inScaled = true;
mOptions.inTargetDensity = getContext().getResources().getDisplayMetrics().densityDpi;
}
mOptions.inDensity = inDensity;
}
use of android.graphics.BitmapFactory.Options in project 9GAG by Mixiaoxiao.
the class Converters method byteArrayToDrawable.
/**
* Converts a byte array into a BitmapDrawable, using the provided options.
*
* @param image The byte array representing the image.
* @param opts The decoding options to use, or null if you'd like to use predefined
* options (scaling will be not active).
* @param context The Context for getting the Resources.
*
* @return The initialized BitmapDrawable.
*/
public static BitmapDrawable byteArrayToDrawable(byte[] image, Options opts, Context context) {
if (opts == null) {
Log.v(TAG, "opts is null, initializing without scaling");
opts = new Options();
opts.inScaled = false;
}
Bitmap bmp = BitmapFactory.decodeByteArray(image, 0, image.length, opts);
// bmp.setDensity(DisplayMetrics.DENSITY_HIGH);
return new BitmapDrawable(context.getResources(), bmp);
}
use of android.graphics.BitmapFactory.Options in project SmartAndroidSource by jaychou2012.
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 SmartAndroidSource by jaychou2012.
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);
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 SmartAndroidSource by jaychou2012.
the class BaseImageDecoder method defineImageSizeAndRotation.
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);
}
Aggregations