我將我的圖像轉換爲字節數組然後轉換爲base64字符串,它完全轉化並解碼,但是當我使用php將該字符串保存到mysql數據庫並從數據庫中檢索它時,它不會解碼並說錯誤base64在android中使用Base64
這是我的代碼。
PHP
$sql = "insert into users(username, password, email,mob,imagetext)
values ('".$username."', '".$password."', '".$email."', '".$mob."', '".$imageText."') ";
機器人
編碼
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);
解碼
byte[] decodedByte = Base64.decode(value, Base64.DEFAULT);
b = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
我認爲它包裝內的MySQL保存之前的字符串。 – Punit
你不提供PHP的解碼功能...... – Leonardo
我將作爲使用PHP編碼和解碼是由Android代碼來處理文本。那是正確的方法嗎?我是編碼新手! – Punit