Added support for BIMI

This commit is contained in:
M66B
2021-07-13 10:37:02 +02:00
parent 3ad79fe6a2
commit f7ffc52747
10 changed files with 240 additions and 70 deletions

View File

@@ -57,6 +57,8 @@ import androidx.core.graphics.ColorUtils;
import androidx.exifinterface.media.ExifInterface;
import androidx.preference.PreferenceManager;
import com.caverock.androidsvg.SVG;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
@@ -242,6 +244,29 @@ class ImageHelper {
return round;
}
@NonNull
static Bitmap renderSvg(InputStream is, int fillColor, int scaleToPixels) throws IOException {
try {
SVG svg = SVG.getFromInputStream(is);
float w = svg.getDocumentWidth();
float h = svg.getDocumentHeight();
if (w < 0 || h < 0) {
w = 1;
h = 1;
}
Bitmap bm = Bitmap.createBitmap(
scaleToPixels,
Math.round(scaleToPixels * h / w),
Bitmap.Config.ARGB_8888);
bm.eraseColor(fillColor);
Canvas canvas = new Canvas(bm);
svg.renderToCanvas(canvas);
return bm;
} catch (Throwable ex) {
throw new IOException("SVG, ex");
}
}
static Drawable decodeImage(final Context context, final long id, String source, boolean show, int zoom, final float scale, final TextView view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean inline = prefs.getBoolean("inline_images", false);