Search in sources :

Example 1 with Options

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

Example 2 with Options

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

Example 3 with Options

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

Example 4 with Options

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

Example 5 with Options

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

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