Procházet zdrojové kódy

ImageUtils: Add optional `type` paramter to `getDataURL()`. (#30751)

Michael Herzog před 10 měsíci
rodič
revize
e6343e89dd

+ 3 - 2
examples/jsm/exporters/GLTFExporter.js

@@ -24,7 +24,8 @@ import {
 	CompressedTexture,
 	CompressedTexture,
 	Vector3,
 	Vector3,
 	Quaternion,
 	Quaternion,
-	REVISION
+	REVISION,
+	ImageUtils
 } from 'three';
 } from 'three';
 
 
 /**
 /**
@@ -1465,7 +1466,7 @@ class GLTFWriter {
 
 
 			} else {
 			} else {
 
 
-				imageDef.uri = canvas.toDataURL( mimeType );
+				imageDef.uri = ImageUtils.getDataURL( canvas, mimeType );
 
 
 			}
 			}
 
 

+ 3 - 2
src/extras/ImageUtils.js

@@ -14,9 +14,10 @@ class ImageUtils {
 	 * Returns a data URI containing a representation of the given image.
 	 * Returns a data URI containing a representation of the given image.
 	 *
 	 *
 	 * @param {(HTMLImageElement|HTMLCanvasElement)} image - The image object.
 	 * @param {(HTMLImageElement|HTMLCanvasElement)} image - The image object.
+	 * @param {string} [type='image/png'] - Indicates the image format.
 	 * @return {string} The data URI.
 	 * @return {string} The data URI.
 	 */
 	 */
-	static getDataURL( image ) {
+	static getDataURL( image, type = 'image/png' ) {
 
 
 		if ( /^data:/i.test( image.src ) ) {
 		if ( /^data:/i.test( image.src ) ) {
 
 
@@ -59,7 +60,7 @@ class ImageUtils {
 
 
 		}
 		}
 
 
-		return canvas.toDataURL( 'image/png' );
+		return canvas.toDataURL( type );
 
 
 	}
 	}
 
 

粤ICP备19079148号