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;
}
Aggregations