【发布时间】:2012-10-23 21:00:30
【问题描述】:
我正在使用此代码将 Bitmap 转换为 Base64:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, **quality**, baos);
byte[] b = baos.toByteArray();
base64code = Base64.encodeToString(b, Base64.DEFAULT);
并以这种方式在服务器端接收它:
$strImage = preg_replace('!\s*!', '', trim($this->input->post('image')));
$thefile = base64_decode($strImage);
$img = imagecreatefromstring($thefile);
//header('Content-Type: image/jpeg');
header('Content-Type: bitmap; charset=utf-8');
imagesavealpha($img, true);
imagejpeg($img,'./images/temp/testing.jpg',100);
imagedestroy($img);
问题:
我从设备库中挑选并发送到服务器的实际图像大小是 344 kb 当我设置 quality = 0 并显示微调对话框实用程序时base64 字符串被发送到服务器需要 5 秒 发送,并且在服务器端接收到的图像是 344 Kb 但如果我设置 quality = 100 发送需要 60-70 秒,我在服务器端收到的图像是 1.7 Mb p>
问题:
为什么我在使用 quality = 0 时得到实际尺寸,而在 quality = 100
时得到几乎 5 倍 图像注意:
当我设置 quality = 100 并更改
imagejpeg($img,'./images/temp/testing.jpg',100);
到
imagejpeg($img,'./images/temp/testing.jpg',10);
发送需要 60-70 秒,但服务器端接收到的图像太小 67 Kb
谢谢
【问题讨论】: