我正在使用它来对位图进行编码和解码,以将照片存储在MySQL数据库中。我将照片作为字符串插入,我想在项目中检索它以显示在CircleImageView中。
public String BitMapToString(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
return Base64.encodeToString(b, Base64.DEFAULT);
}
public Bitmap StringToBitMap(String encodedString) {
try {
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
} catch (Exception e) {
e.getMessage();
return null;
}
}
这就是我所说的:
String fotoFromDB = studentFromDB.getFotoStringStudent();
Bitmap bitmap = StringToBitMap(fotoFromDB); //in the debbuger here says that bitmap==null
profilePic.setImageBitmap(bitmap);
String fotoFromDB = iVBORw0KGgoAAAANSUhEUgAAAjEAAAOwCAIAAABAlrJqAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4 nOy9WZckx5WYee81c/dYMrMysxaCAEHsG0mAa7NJEFKv6m5pelrS0YPOzB8Y9Tyq9RNmXuZBZ/6A ztGcOXNmXlpnRupNvVHdbIIgWSD2hUBVAShUYak9l1jc3ezeefDIKE9fIjwiPLYs+04RjIwwN7u2 XrvXFsdPPnsDHOsDIi5bhJkQkcLvy/KVhE//upolYK0dGyYtuVIKjpdGPqeLR0SGIiWSDOUpq7gy ZszIpMmtO/dafssQEb1sGRyONWbqoWRdxqB1kdNxYnA6yeGYkpM9XosIItZlNjkcFXE6yeGYhuGg PN3onH9q6T7JtONu+A0zDwVLf5i3Tpq0NJyOPDHQsgVwONaJzFgpR0waz9QPzonMylZ+oSv9/eqI 7ThhIKLTSQ7HlMwyRq/s+F5mwA2lXSlV6jh5ON+dwzEZGc/V1L67JJ6lu+zKSGRLizdUS5nv54Hz 3d2zODvJ4ZiVGZeUVmQ8LRQDjxgb0uGoBWcnLZmVnSZnKBuGiOY7rcmXz2LO8VSJP73mP4s8I05f DU2TeZRz4emooRWY+O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9yYaSprsRH5kZzA55kRFw33eA9/YFp647BIxkh13FhEQOTIsli2jMBASIhIiIh8dWRJM/nfMfsm7 IibdC14YQKTQNlsE66KZ1kXOE4xO2nq6JvInOdJkJo9DP
问题是,当我尝试将此代码转换回位图时,它不起作用。