mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-04 18:48:31 +00:00
Handle broken image data URIs
This commit is contained in:
parent
f5f70ae073
commit
0f4db07e40
1 changed files with 20 additions and 14 deletions
|
@ -141,23 +141,29 @@ public class HtmlHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data URI
|
// Data URI
|
||||||
if (data) {
|
if (data)
|
||||||
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" +
|
try {
|
||||||
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
|
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" +
|
||||||
// "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
|
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
|
||||||
// "5ErkJggg==\" alt=\"Red dot\" />";
|
// "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
|
||||||
|
// "5ErkJggg==\" alt=\"Red dot\" />";
|
||||||
|
|
||||||
String base64 = source.substring(source.indexOf(',') + 1);
|
String base64 = source.substring(source.indexOf(',') + 1);
|
||||||
byte[] bytes = Base64.decode(base64.getBytes(), 0);
|
byte[] bytes = Base64.decode(base64.getBytes(), 0);
|
||||||
|
|
||||||
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||||
if (bm == null)
|
if (bm == null)
|
||||||
throw new IllegalArgumentException("decode byte array failed");
|
throw new IllegalArgumentException("decode byte array failed");
|
||||||
|
|
||||||
Drawable d = new BitmapDrawable(context.getResources(), bm);
|
Drawable d = new BitmapDrawable(context.getResources(), bm);
|
||||||
d.setBounds(0, 0, bm.getWidth(), bm.getHeight());
|
d.setBounds(0, 0, bm.getWidth(), bm.getHeight());
|
||||||
return d;
|
return d;
|
||||||
}
|
} catch (IllegalArgumentException ex) {
|
||||||
|
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||||
|
Drawable d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme());
|
||||||
|
d.setBounds(0, 0, px / 2, px / 2);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
// Get cache folder
|
// Get cache folder
|
||||||
File dir = new File(context.getCacheDir(), "images");
|
File dir = new File(context.getCacheDir(), "images");
|
||||||
|
|
Loading…
Add table
Reference in a new issue