我有摄像头记录意图,当结果没问题时,我尝试将此视频转换为byte []以发送网络服务:
我这样做:
if (resultCode == RESULT_OK) {
// Video guardado
videoUri = data.getData();
if (videoUri != null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileInputStream fichero_codificar = null;
try {
fichero_codificar = new FileInputStream(
videoUri.getPath());
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fichero_codificar.read(buf))) {
out.write(buf, 0, n);
}
byte[] videoByte = out.toByteArray();
strBase64 = Base64.encode(videoByte);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但是在fichero_codificar = new FileInputStream( videoUri.getPath())
logcat说我文件不存在或补丁不存在。
任何人都有我的qustion的例子吗? 感谢
答案 0 :(得分:0)
看起来你发现的信息不正确。以下是我在我的应用程序中使用Camera意图的方法:
thumbnail = (Bitmap) data.getExtras().get("data");
try {
FileOutputStream out = new FileOutputStream(getPicName(index));
thumbnail.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
所以也许可以尝试使用Video对象而不是Bitmap对象。 如果这不起作用,你可以试试.getAbsolutePath()。
是的,它绝对没有做你认为它做的事情。我在我的上运行了调试器,getPath返回了这个:/external/images/media/21
,这是一个内容Uri。