Browse Source

Merge pull request #15255 from Mugen87/dev11

ImageUtils: Create internal canvas only once
Mr.doob 6 năm trước cách đây
mục cha
commit
37d4274573
1 tập tin đã thay đổi với 9 bổ sung4 xóa
  1. 9 4
      src/extras/ImageUtils.js

+ 9 - 4
src/extras/ImageUtils.js

@@ -4,6 +4,8 @@
  * @author szimek / https://github.com/szimek/
  */
 
+var _canvas;
+
 var ImageUtils = {
 
 	getDataURL: function ( image ) {
@@ -20,11 +22,12 @@ var ImageUtils = {
 
 		} else {
 
-			canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
-			canvas.width = image.width;
-			canvas.height = image.height;
+			if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
+
+			_canvas.width = image.width;
+			_canvas.height = image.height;
 
-			var context = canvas.getContext( '2d' );
+			var context = _canvas.getContext( '2d' );
 
 			if ( image instanceof ImageData ) {
 
@@ -36,6 +39,8 @@ var ImageUtils = {
 
 			}
 
+			canvas = _canvas;
+
 		}
 
 		if ( canvas.width > 2048 || canvas.height > 2048 ) {