Search in sources :

Example 6 with Options

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;
}
Also used : Options(android.graphics.BitmapFactory.Options) Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream)

Example 7 with Options

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;
}
Also used : ImageScaleType(com.nostra13.universalimageloader.core.assist.ImageScaleType) Options(android.graphics.BitmapFactory.Options) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize)

Example 8 with Options

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);
}
Also used : Options(android.graphics.BitmapFactory.Options)

Example 9 with 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);
}
Also used : Options(android.graphics.BitmapFactory.Options) Point(android.graphics.Point)

Example 10 with Options

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);
            }
        }
    }
}
Also used : Options(android.graphics.BitmapFactory.Options) RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException)

Aggregations

Options (android.graphics.BitmapFactory.Options)30 Bitmap (android.graphics.Bitmap)12 IOException (java.io.IOException)10 BitmapFactory (android.graphics.BitmapFactory)6 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)4 File (java.io.File)3 Matrix (android.graphics.Matrix)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 ExifInterface (android.media.ExifInterface)2 Handler (android.os.Handler)2 ImageSize (com.nostra13.universalimageloader.core.assist.ImageSize)2 ImageSize (com.smartandroid.sa.zUImageLoader.core.assist.ImageSize)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileDescriptor (java.io.FileDescriptor)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2