![](/img/trans.png)
[英]Using Phonegap download image and want to convert it into base64 in iOS
[英]How to convert video to base64 using jquery and phonegap
在這里,我已經使用phonegap用JavaScript編寫了代碼,但是無法在base64中獲取視頻數據
function captureVideo()
{
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1});
}
function captureSuccess(mediaFiles)
{
console.log(JSON.stringify(mediaFiles));
console.log("HERE I WANT BASE64 CODE");
}
要從視頻幀中獲取數據uri,您必須先將其繪制到canvas元素上(以及確保滿足CORS要求)。
我對Cordova不太熟悉,但希望它能使您朝正確的方向前進:
// create a canvas element
var canvas = document.createElement('canvas'), // canvas
ctx = canvas.getContext('2d'), // context
video = document.getElementById('myVideoId'); // get video element somehow
// setup canvas dimension
canvas.width = video.videoWidth || video.width;
canvas.height = video.videoHeight || video.height;
// draw in current video frame
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
// extract data-uri
var dataUri = canvas.toDataURL(); // PNG is default, use image/jpeg for JPEG
如果需要多次執行此操作,則只需設置一次畫布,並在需要框架時使用drawImage
/ toDataURL
調用。
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.