Cách Convert Base64 về Bitmap để hiển thị hình ảnh trong android

hiện em có 1 đoạn mã base64 như sau

data:image/jpeg;base64,%2F9j%2F4AAQSkZJRgABAQEAAAAAAAD%2F2wBDAAoHCAkIBgoJCAkLCwoMDxkQDw4ODx8WFxIZJCAmJiQgIyIoLToxKCs2KyIjMkQzNjs9QEFAJzBHTEY%2FSzo%2FQD7%2F2wBDAQsLCw8NDx0QEB0%2BKSMpPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj7%2FxAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv%2FxAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5%2Bjp6vHy8%2FT19vf4%2Bfr%2FxAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv%2FxAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4%2BTl5ufo6ery8%2FT19vf4%2Bfr%2FwAARCAEoAZADASEAAhEBAxEB%2F9oADAMBAAIRAxEAPwDyw8cc80z%2BKj4nqFuUkj2buR0qYgbuQM%2FSq5Eh8g0hQCdn1NKqL%2FcHSjzG0w2Iq5ZRxSARnolNalDsRhvljDH%2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xTT1pS10EMNQlwKRT1ZXaTrio1mPcCtClG5%2F%2FZ

em đã thử cách này :

final String encodedString = "data:image/jpg;base64, ....";                        
final String pureBase64Encoded = encodedString.substring(encodedString.indexOf(",")  + 1);
final byte[] decodedBytes = Base64.decode(pureBase64Encoded, Base64.DEFAULT);
Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);

và cả cách này

String base64String = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAA...";
String base64Image = base64String.split(",")[1];

byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);

nhưng em cứ gặp lỗi

bad-base64 

hoặc lỗi

Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference

Em đang bí quá, mong anh chị chỉ em hướng đi khúc này với ạ :<
em cảm ơn nhiều

Trong Base64 không có kí tự %, đây là kí tự đã mã hóa của url.
%2F là kí tự /.

4 Likes

Vậy em phải replace %2F thành / hay sao ạ ?

Đúng vậy. Đúng là thế.

Em đã làm vậy

String b = data.replaceAll("%2F","/").replace(“data:image/jpeg;base64,”,"").replaceAll("%","");

sau đó thì

byte[] c = b.getBytes();
byte[] decodedString = Base64.decode(c, Base64.DEFAULT);

nhưng khi đến bước

Bitmap bitmapImage = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

thì lại trả về null khiến cho .setImageBitmap(bimapImage) không hoạt động ạ ?

em mong anh chỉ giáo

  1. Cậu nên dùng URLDecoder để decode URL, thay vì replace.
    Nếu cậu dùng Java 10+:
String result = java.net.URLDecoder.decode(url, StandardCharsets.UTF_8);
  1. Ảnh của cậu là ảnh png, nên có lẽ cậu phải convert nó sang bmp trước.
    Thử lưu ảnh dưới dạng png trước, rồi đọc lại và lưu dưới dạng bmp xem cậu.
    Tớ cũng không rõ có cách nào khác để convert không, cậu thử tìm hiểu thêm nhé!

Hope it helps!

8 Likes

Dạ em cũng đã thử URLDecoder
nhưng cứ đến đoạn Bitmap nó lại trả về null
ảnh của em lưu trên Database nên em đang muốn get về máy Android - chứ ko phải ảnh có sẵn xong mình cvert qua bmp ạ :<

Ừ tớ hiểu :smile:

Ý tớ là:

  • đoạn string được encode base64 là byte stream của ảnh PNG (cậu thấy đoạn “data:image/png;” chứ? :smile:) Cậu đang đọc nó dưới bằng BitmapFactory => sao cậu kỳ vọng byte stream của PNG có thể chuyển thành Bitmap được? :smile:
  • URLDecoder là để convert mấy đoạn %2F (hay các mã khác) thành ký tự gốc, từ đó cậu mới chuyển nó thành byte stream để convert sang ảnh được.
    Nó là bước tiền xử lý, đừng nhầm lẫn nhé cậu! :smile:

Để tối tớ thử trên máy tính xem sao.

7 Likes

Bạn nên kiểm tra và chắc rằng mảng byte[] chứa dữ liệu đã giải mã chứa dữ liệu và dữ liệu phải tương đương với 3/4 độ dài của chuỗi Base64.
Từ tài liệu của BitmapFactory.decodeByteArray

The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight)

Điều này dẫn đến 1 khả năng khác: đã giải mã thành công, nhưng dữ liệu hình ảnh bị sai định dạng hoặc bị hư hại.

Lưu ý: Bảng tạm (Clipboard) có thể có giới hạn, nếu bạn sao chép chuỗi có độ dài quá lớn, chuỗi sẽ bị cắt bớt. Base64 còn lớn gấp 4/3 dữ liệu gốc, nếu hình ảnh có độ lớn vài MB thì đảm bảo không đủ chỗ cho bạn sao chép chuỗi đó trong 1 lần chép, dán.
Mà cũng chẳng dám chắc là url trên trình duyệt hiển thị đủ chuỗi hay không.

7 Likes

Dạ ảnh của em chỉ khoảng 13kb thôi ạ, và em có vào trang
https://codebeautify.org/base64-to-image-converter
để dán thử đoạn mã vào thì ảnh vẫn hiện bình thường, khi em kiểm tra mảng byte[] vẫn có dữ liệu, chắc có lẽ đã sai ở bước nào rồi ạ

1 Like

Trong Base64 còn có 2 kí tự đặc biệt nữa mà khi hiển thị trên url thì nó sẽ biến đổi về dạng %XX, đó là +=.
Bạn phải đảm bảo dữ liệu giải mã về đúng dữ liệu gốc, không sai một byte, một bit nào.

3 Likes

Tớ có thử code dưới đây:

import java.io.ByteArrayInputStream;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

import javax.imageio.ImageIO;
...

  @Test
  public void testStoreImage() throws Exception {
    String data = "data:image/jpeg;base64,%2F9j%2F4AAQSkZJRgABAQEAAAAAAAD%2F2wBDAAoHCAkIBgoJCAkLCwoMDxkQDw4ODx8WFxIZJCAmJiQgIyIoLToxKCs2KyIjMkQzNjs9QEFAJzBHTEY%2FSzo%2FQD7%2F2wBDAQsLCw8NDx0QEB0%2BKSMpPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj4%2BPj7%2FxAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv%2FxAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5%2Bjp6vHy8%2FT19vf4%2Bfr%2FxAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv%2FxAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ub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g7HpRtOevFFxPUO9KKaCUQ70UXsG6HY9KmjX5aXNqEFYlHSnjGK0HbUeM9qdIP3VQ5DciKKphRszPzJUXmp4TRIRIBzxSTD9aEzKWhmv95qrPQtWbeZH36%2FhSdqcigopb6lRDFFNMVx%2FalWmG%2Bg6pEPNPcFuXrc8itqA%2FIBT8gntclptDIuJ70lAXuNxTT1pS10EMNQlwKRT1ZXaTrio1mPcCtClG5%2F%2FZ";
    byte[] decoded = Base64.getDecoder().decode(java.net.URLDecoder.decode(data, StandardCharsets.UTF_8).split(",")[1]);
    try (var bis = new ByteArrayInputStream(decoded)) {
      ImageIO.write(ImageIO.read(bis), "bmp", new File("/path/to/the/test.bmp"));
    }
  }

Kết quả:

Cậu thử tham khảo code trên xem nha :smile:

4 Likes

chỗ decode có flag Base64.URL_SAFE khỏi cần qua url decoder :triumph:

edit: Java 8 có Base64.getUrlDecoder() :V

8 Likes

Ohm, tớ có thử test với Base64.getUrlEncoder() lúc sáng, nó có vẻ không hoạt động.
Cân nhắc nhé @Huy_Tran_Duc :smile:

7 Likes

Dạ em cảm ơn, cái của anh làm là lưu ảnh vào local storage của máy luôn nhỉ. Khi em làm thì có vẻ ImageIO chưa import được

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?