canvas 이미지 복사시 고려할 사항

2021. 1. 24. 19:31Javascript

canvas를 초기화하면 original_canvas도 같이 초기화 됨

            canvas = tiff.toCanvas();
            canvas.setAttribute('id','tiff')
            context = canvas.getContext('2d')
			original_canvas = canvas
            
            
            function clearImage() {
                context.clearRect(0,0,canvas.width,canvas.height)
            }
            
            
			function copy() {
                var temp = $('#test')[0];
                console.log(temp)
                cont = temp.getContext('2d')
                var img = new Image()
                img.onload = function() {
                    console.log('afas')                    
                    cont.drawImage(img, 0, 0, temp.width, temp.height)
                    console.log('afas')                    
                }
                console.log(original_canvas.toDataURL())
                img.src = original_canvas.toDataURL()
            }