[英]Decode image from base64 string
我正在從base64字符串中將圖像發送到php服務器。 從服務器端檢索它時,它會顯示圖像的大小,但不會顯示我發布到服務中的圖像。 我正在使用post方法發送字符串。
我的android code://編碼圖像。
Bitmap bm=BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
PHP代碼://解碼圖像
$string=$_POST ['i_image'];
$filename="newimage.jpg";
$imagepath=base64_to_jpeg($string,$filename);
function base64_to_jpeg($base64_string, $output_file) {
$ifp = fopen($output_file, "wb");
$data = explode(',', $base64_string);
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $output_file;
}
誰能幫我找回原圖?
提前致謝。
如果您想用PHP解碼圖像,我認為這將對您有所幫助
$uploadDir = 'path/to/download/dir/';
$binary = base64_decode($data_encoded_base64);
header('Content-Type: bitmap; charset=utf-8');
$fileName=md5(uniqid()).'.png';
$file = fopen($uploadDir . $fileName, 'wb');
fwrite($file, $binary);
fclose($file);
希望對您有幫助,祝您好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.