[英]android image to base64 string, and send to php
im using this code in the android app, to capture image from camera and send to a javascript file to send a php controller for create file and inset some info to mysql. 即时通讯在Android应用程序中使用此代码,以捕获来自相机的图像并发送至JavaScript文件,以发送用于创建文件的PHP控制器,并将一些信息插入到MySQL中。
the process works fine but the result image is to small and really poor quality 该过程运行良好,但结果图像很小,质量很差
if( ACTION_TAKE_PICTURE == requestCode )
{
Bundle extras = intent.getExtras();
Bitmap bitmap;
if( null == extras || null == (bitmap=(Bitmap)extras.get("data")) ) return;
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
byte [] ba = out.toByteArray();
String b64img = Base64.encodeToString(out.toByteArray(), Base64.NO_WRAP);
try { out.close(); } catch(Exception e) {}
wv.loadUrl( String.format("%s%s('%s')", getString(R.string.js_call_prefix), getString(R.string.js_callback_camera), b64img ));
}
the php code is: php代码是:
public function executeImagen(sfWebRequest $request) {
$id = $request->getParameter('id');
$img = $request->getParameter('img');
$category = $request->getParameter('category');
$user = $this->getUser()->getAttribute('id_users');
try {
$basepdir = $path = sfConfig::get("sf_upload_dir") . '/photos/';
$basename = date('Ymd_His');
$buffer = base64_decode(str_replace(' ', '+', $img));
$pname = sprintf("%s%s.JPG", $basepdir, $basename);
$photo = sprintf("%s.JPG", $basename);
$fd = fopen($pname, "wb");
if ($fd) {
fwrite($fd, $buffer);
fflush($fd);
fclose($fd);
}
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
try {
$tabla = Doctrine::getTable('StorePhotos');
$tabla = new StorePhotos();
$tabla->id_store = $id;
$tabla->id_category = $category;
$tabla->id_users = $user;
$tabla->imagen = $photo;
$tabla->photo_date = date('Y-m-d H:i:s');
$tabla->save();
} catch (Exception $e) {
trigger_error("ERROR: ", $e->getMessage());
}
return sfView::NONE;
}
thanks. 谢谢。
You are getting and sending the thumbnail. 您正在获取并发送缩略图。 You need to retrieve the full-size image from disk instead. 您需要从磁盘检索全尺寸图像。 Read this guide by Google. 阅读Google的本指南 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.