Google glass 在GDK中将图像转换为base64
我目前正在将映像作为Base64传递给rest服务。但是我看不懂文件。这是我的密码:Google glass 在GDK中将图像转换为base64,google-glass,google-gdk,Google Glass,Google Gdk,我目前正在将映像作为Base64传递给rest服务。但是我看不懂文件。这是我的密码: if(requestCode==iPictureCode&&resultCode==RESULT\u确定){ String picturePath=data.getStringExtra(Intents.EXTRA\u PICTURE\u FILE\u PATH); 字符串image=processPictureWhenReady(picturePath); } `私有字符串进程PictureWhenRead
if(requestCode==iPictureCode&&resultCode==RESULT\u确定){
String picturePath=data.getStringExtra(Intents.EXTRA\u PICTURE\u FILE\u PATH);
字符串image=processPictureWhenReady(picturePath);
}
`私有字符串进程PictureWhenReady(最终字符串picturePath){ 最终文件pictureFile=新文件(picturePath) }` 它从不为“pictureFile.exists()”进入if块
可能是什么问题?看起来您从中修改了代码,但删除了
else
子句,其中使用FileObserver
来检测图像何时实际可用。你也需要这个部分,因为当活动返回时,完整大小的图像可能不会立即准备好。谢谢@Tony的回复…我删除了我问题中的那段代码…但是现在我用EXTRA\u PICTURE\u FILE\u PATH
替换EXTRA\u THUMBNAIL\u FILE\u PATH
时,它对我起作用了当返回“活动结果”时,请始终立即准备就绪,因此,如果您只需要低分辨率图像,您可以直接使用它。但是,如果需要,您仍然需要FileObserver
来检测全尺寸图像。缩略图立即可用的原因是,您可以在UI中显示一些内容,以确认图片是在准备完整图像时拍摄的。感谢@TonyAllevato的帮助:)
if (pictureFile.exists()) {
// The picture is ready; process it.
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
bitmap = CameraUtils.resizeImageToHalf(bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, stream);
String base64Image = Base64.encodeToString(stream.toByteArray(), Base64.DEFAULT);
return base64Image;
}