浏览代码

fixed the base64 MIME type when JPG is chosen

valid MIME type for JPEG / JPG images is "image/jpeg" 
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#Image_types
This was causing Android not to recognize the screenshots taken by this library
Ardavan Kalhori 6 年前
父节点
当前提交
6942e05c65
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4
    0
      android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

+ 4
- 0
android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java 查看文件

@@ -107,6 +107,10 @@ public class ViewShot implements UIBlock {
107 107
                 captureView(view, os);
108 108
                 byte[] bytes = ((ByteArrayOutputStream) os).toByteArray();
109 109
                 String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
110
+                // correct the extension if JPG
111
+                if (extension != null && extension.equals("jpg")) {
112
+                    extension = "jpeg";
113
+                }
110 114
                 data = "data:image/"+extension+";base64," + data;
111 115
                 promise.resolve(data);
112 116
             }