uniapp中使用原生canvas标签绘制视频帧来模拟拍照,拍照后将图绘制在另外一个canvas上编辑画图,这样反复操作

uniapp中使用原生canvas标签绘制视频帧来模拟拍照,拍照后将图绘制在另外一个canvas上编辑画图,这样反复操作会导致ios系统上白屏,canvas2d上下文为null,经查阅找到相关资料
IOS 创建Canvas过多导致getContext('2d') 返回null
总 Canvas 内存使用超过最大限制 (Safari 12)
从一个 bug 中延伸出 canvas 最大内存限制和浏览器渲染原理

可以提供一些启发解决思路,最终在项目中这样解决的

bash 复制代码
beforeDestroy() {
	this.timer && clearInterval(this.timer);
	this.closeCamera()
	this.video = null
	if(this.canvas){
		this.canvas.width = 0
		this.canvas.height = 0
		this.canvas = null
		this.canvas2d = null
	}
	if(this.cameraCanvas){
		this.cameraCanvas.width = 0
		this.cameraCanvas.height = 0
		this.cameraCanvas = null
		this.cameraCanvas2d = null
	}
},

项目中还用了fabricjs,同样需要

bash 复制代码
fabricCanvasDispose() {
	console.log('释放内存')
	if (this.fabricCanvas) {
		let el = this.fabricCanvas.getElement()
		this.fabricCanvas.dispose();
		el.remove()
		this.fabricCanvas = null;
	}
	if (this.canvas) {
		this.canvas.width = 0
		this.canvas.height = 0
		this.canvas = null;
		this.canvas2d = null;
	}
}
相关推荐
2501_915918412 小时前
iOS 手机抓包软件怎么选?HTTPS 调试、TCP 数据流分析与多工具组合的完整实践
android·ios·智能手机·小程序·https·uni-app·iphone
游戏开发爱好者82 小时前
iOS 应用上架的工程实践复盘,从构建交付到审核通过的全流程拆解
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张2 小时前
iOS App 如何上架,从准备到发布的完整流程方法论
android·macos·ios·小程序·uni-app·cocoa·iphone
Json____2 小时前
uni-app-数码购物商城h5手机端-前端静态网页
前端·uni-app·商城
wx_xsooop3 小时前
iOS 上架4.3a 被拒【uniapp专讲】
flutter·ios·uni-app·uniapp
脾气有点小暴21 小时前
uniapp滚动容器冲突
uni-app
鱼樱前端1 天前
uni-app开发app之前提须知(IOS/安卓)
前端·uni-app
二狗mao2 天前
Uniapp使用websocket进行ai回答的流式输出
websocket·网络协议·uni-app
良逍Ai出海2 天前
Build in Public|为什么我开始做一款相册清理 App(听说有竞品年收益40W)
ios·uni-app·ai编程·coding
2501_915106324 天前
iOS App 测试工具全景分析,构建从开发调试到线上监控的多阶段工具链体系
android·测试工具·ios·小程序·uni-app·iphone·webview