Search in sources :

Example 1 with InputStreamBitmap

use of com.foobnix.sys.InputStreamBitmap in project LibreraReader by foobnix.

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;
    }
    if (imageStream instanceof InputStreamBitmap) {
        decodedBitmap = ((InputStreamBitmap) imageStream).getBitmap();
        imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
        decodedBitmap = considerExactScaleAndOrientatiton(decodedBitmap, decodingInfo, imageInfo.exif.rotation, imageInfo.exif.flipHorizontal);
        L.d("decode InputStreamBitmap", decodingInfo.getImageKey());
        return decodedBitmap;
    }
    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) InputStreamBitmap(com.foobnix.sys.InputStreamBitmap) Bitmap(android.graphics.Bitmap) InputStreamBitmap(com.foobnix.sys.InputStreamBitmap) InputStream(java.io.InputStream)

Aggregations

Bitmap (android.graphics.Bitmap)1 Options (android.graphics.BitmapFactory.Options)1 InputStreamBitmap (com.foobnix.sys.InputStreamBitmap)1 InputStream (java.io.InputStream)1