私は自分の chrome アプリに取り組みましたが、コンテンツのセキュリティ ポリシーに神経質になりました。json (string/object/array I don't know)から jpeg 画像を取得したかったのですが、csp は毎回私を止めました。データリンクの方が簡単だとわかったので、コンバーターを検索しました。
function getdt(img) {
// Create an empty canvas element
var canvas = document.createElement("canvas");
// Copy the image contents to the canvas
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
// Get the data-URL formatted image.
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
//Example
getdt('http://ms01.oe3.fm/oe3metafiles/Pictures/200/929203.22.jpg');
残念ながら、これは機能しません。エラーメッセージは次のとおりです。
Uncaught TypeError:
Failed to execute 'drawImage' on 'CanvasRenderingContext2D':
No function was found that matched the signature provided.
誰かが私を助けてくれることを願っています:) 私の悪い英語でごめんなさい