本文共 1729 字,大约阅读时间需要 5 分钟。
* 视屏转Base64字符串 * @param * @return */ private String fileBase64String(Uri url){ try { InputStream fis = getContentResolver().openInputStream(url);;//转换成输入流 ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int count = 0; while((count = fis.read(buffer)) >= 0){ baos.write(buffer, 0, count);//读取输入流并写入输出字节流中 } fis.close();//关闭文件输入流 return Base64.encodeToString(baos.toByteArray(),Base64.DEFAULT); } catch (Exception e) { Log.e(TAG, "错误--> " + e); return null; } }
/** * base64字符串转视屏 * videoFilePath 输出视频文件路径带文件名 */ public static void base64ToVideo(String base64) { try { //base解密 byte[] videoByte = Base64.decode(base64.getBytes(),Base64.DEFAULT); File videoFile = new File(Environment.getExternalStorageDirectory() + "/Convert.mp4"); if (videoFile.exists()){ videoFile.delete(); } try { //创建文件 videoFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); Log.e("creatXMLFileException",e.getMessage()); } //输入视频文件 FileOutputStream fos = new FileOutputStream(videoFile); fos.write(videoByte, 0, videoByte.length); fos.flush(); fos.close(); Log.d(TAG,"视屏保存的地址--" + videoFile); } catch (IOException e) { Log.e(TAG,"base64转换为视频异常",e); } }
转载地址:http://vsfa.baihongyu.com/