在 Javascript 中将 Base64 数据转换并插入到 Canvas

Convert and insert Base64 data to Canvas in Javascript(在 Javascript 中将 Base64 数据转换并插入到 Canvas)

本文介绍了在 Javascript 中将 Base64 数据转换并插入到 Canvas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个数据缓冲区,代表 Base64 中的图像.我得到的数据(以base64表示图像)(部分数据)

<代码> 193,1181,25,21,211 ,111111,211,2111111111111111111111111111118.11111111111151515151584,103,136,198,74,212,41,171,203,188,187,69,121,183,255,0,7,75,156,191,140,​​190,45,181,219,141,43,195,214,107,30,129,3,145,38,110,60,135,185,35,130,119,4,108,244,238,0,227,3,140,​​86,85,237,134,149,241,3,69,158,251,71,134,93,31,88,211,72,82,1,30,100,76,70,65,12,9,12,141,207,94,184,32,140,​​215,45,47,196,111,130,177,187,34,120,79,197,65,84,224,8,175,03,20,97,426,785,141,47,227,159,195,111,11,219,223,46,133,225,175,17,91,73,120,170,178,189,196,137,49,96,185,218,50,247,44,64,27,155,167,173,123,252,61,144,97,242,8,63,102,156,234,207,227,169,43,115,77,245,230,119,122,111,104,173,23,78,167,204,103,121,165,108,217,46,88,184,40,124 .....

成功解码.

现在我正在尝试将图像添加到我的画布但没有成功,如下所示:

function fillCanvasImage(x, y, width, height, image, pageID) {如果(图像==")返回;var canvas = document.getElementById("AppPmainCanvas" + pageID);if (canvas && canvas.getContext) {var context = canvas.getContext('2d');如果(上下文){context.clearRect(0, 0, canvas.width, canvas.height);var img = new Image();img.src = base64_decode(图像);//img.onload = function () {context.drawImage(img, 0, 0, canvas.width, canvas.height);/

本文标题为:在 Javascript 中将 Base64 数据转换并插入到 Canvas

基础教程推荐