Search in sources :

Example 1 with SkiaImageDecoder

use of com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder in project Signal-Android by WhisperSystems.

the class AttachmentBitmapDecoder method decode.

@Override
public Bitmap decode(Context context, Uri uri) throws Exception {
    if (!PartAuthority.isLocalUri(uri)) {
        return new SkiaImageDecoder().decode(context, uri);
    }
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
    if (masterSecret == null) {
        throw new IllegalStateException("Can't decode without secret");
    }
    InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, uri);
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
        if (bitmap == null) {
            throw new RuntimeException("Skia image region decoder returned null bitmap - image format may not be supported");
        }
        return bitmap;
    } finally {
        if (inputStream != null)
            inputStream.close();
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) SkiaImageDecoder(com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder) BitmapFactory(android.graphics.BitmapFactory)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 SkiaImageDecoder (com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder)1 InputStream (java.io.InputStream)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1