convert base64 to image in javascript/jquery(在 javascript/jquery 中将 base64 转换为图像)
问题描述
我已经编写了一些使用 javascript/jquery 进行图像捕获的代码下面是代码:
I have written some code for image capturing using javascript/jquery Below is the code:
function capture_image(){ 
    alert("capture_image");
    var p = webcam.capture();
    webcam.save();           
    alert("capture complete "+p); //getting true here
     var img = canvas.toDataURL("image");
    var item_image = img.replace(/^data:image/(png|jpg);base64,/, "") ; 
    alert("item_image"+item_image);
}
item_image 打印 base64 格式,如何将该 base64 转换为图像以及如何在 javascript 客户端中使用该路径.
The item_image print the base64 format, How to convert that base64 to image and how to use that path in javascript clientside.
我正在谷歌搜索这么多网站,但它无法正常工作,并且该代码不适合我的要求.
Am searching google so many websites but its not working and that code is not suitable for my requirement.
推荐答案
你可以只创建一个 Image 对象并将 base64 作为它的 src,包括 >data:image... 部分 像这样:
You can just create an Image object and put the base64 as its src, including the data:image... part like this:
var image = new Image();
image.src = 'data:image/png;base64,iVBORw0K...';
document.body.appendChild(image);
这就是他们所说的数据 URI",这里是 兼容性表,让您内心平静.
It's what they call "Data URIs" and here's the compatibility table for inner peace.
这篇关于在 javascript/jquery 中将 base64 转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 javascript/jquery 中将 base64 转换为图像
				
        
 
            
        基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
 - Node.js 有没有好的索引/搜索引擎? 2022-01-01
 - 每次设置弹出窗口的焦点 2022-01-01
 - 什么是不使用 jQuery 的经验技术原因? 2022-01-01
 - Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
 - 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
 - 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
 - WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
 - jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
 - 如何使用 CSS 显示和隐藏 div? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				