Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google glass 在GDK中将图像转换为base64_Google Glass_Google Gdk - Fatal编程技术网

Google glass 在GDK中将图像转换为base64

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

我目前正在将映像作为Base64传递给rest服务。但是我看不懂文件。这是我的密码:

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;
    }