在我的程序(Cordova)中,我使用联系人照片。为了避免将其存储在外部存储器中的其他操作,我决定将图像转换为Base64图像并将它们保存为SharePrefrences中的String Json。
以下是我从图像124x124 长度7231字符获得的示例:
data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYF\nBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoK\nCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCABgAGADASIA\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDzPX/D\nWlX1h/Z+pWH2jz7fyun9+q/h/wAD6D4QsbfRtE0D7Nbf88Lb5P3tegR+A7nUiR/z3/8AINZ3hH9n\nrxpYa2b/AP4WXq17bf8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iD9/qeqWv7y5lH/LJP7iD/vquiNyfF99/Zmfstt/y8H/cz/322z5a37Sz/s3Tzp3/\nAC7H91X0GSZT7KHPiffme1nGPp1p8lH3Da8E+ET9hOsjm9uP3tv/AMD/AOWX/wATW5od3pS65bac\nun83GoSS/wDPPMcn3/8AgStWb8N9V0ptBuQzf8e1xJ/pP+4+yrerSDT/ALPqXhs8i482D/pjs/8A\nZWr2s/yLD5plPJD7B5OX4/EYDHQmdV+1F+ztqvxS+Gx1nwif+Kg0e3/0D/SvLjv4+f8AR5n/APQf\n7rf71eL/AAJ/bw1Xw8194D+Kmn/ara3/AHV9o+qWqRyW3ybPKdPmbcG+Xd/Fu+Wvrr4W+OdL8Y+F\nLbUdM/49p/3U9v8A88ZE+/F/vVwXxw/Zu/Z5+KV+dZ8XfDTTb65/5+P9XeRf7kqfNt/2a/KMPSWG\n9yZ9fKXP78Dxb4vftm+Cvhd4Suj8K/7NsftH2iKDFr5fk7H+T5P4/wCL5v8Aar5u0bRfGPxy1638\nc/FPULk/2vcRw2Nv/wAtJo9+9/8Avpfl2/7Rr2P4tfAv9nrwfrmPDXwz021uT/y3y8kk0u//AGy3\n+9/vU8/D3X9QvtB8Vanp/wDo39seaf8ArnGlYQmsTmMKMP5jqhTcMDOtWJvHn7PXwq+KHhO2sPFv\ngy2ufs9v5UFxa/ubiHZ9yJHT+FV+VVr5V+MX7DXjLwcLrWvhdqA1ixgPzWZ+W5h5/KSvte3n1Xw9\nYW+olf8ARp7j9xz/ALf/AMTVDWLT/TrfxD0+0f8Aoz56/TauW061P3D4uXspn5f3Wlanp17LYalY\nNbTQH97b3A8tl/Bqp1+jfxi+DngT4g6eT4k8HW19a/637R/q7iH/AHJU/wD2a+Q/2lP2adT+Dps/\nFWii5uvD+sA/YbuX70MnP7h/+Aj5W/irwq+FqYepyGbp2p85/9k=\n
但是,如果用户有大约600个联系人,这种方法会让我java.lang.OutOfMemoryError
对strig进行操作,例如:StringBuilder.toString()
或JOSNArray.toString()
等等。
这有什么方法可以缩短base64字符串?
我试图减少图像宽度/高度,但我在这里失去了图像质量。
有什么建议吗?
答案 0 :(得分:1)
简单回答:否则只使用base64。
但你可以:
使用更高的“基数”:例如base85或其他算法:binary to text encoding algorithms
在base64字符串上使用某种压缩算法,例如gzip