Skip to content

Commit

Permalink
Get image url from texture's nativeUrl parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
olga-salina committed Dec 6, 2023
1 parent 7b83a0e commit 92eafca
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { assetManager, ImageAsset, SpriteFrame, Texture2D } from "cc";
export class ImageUtils {

static getBase64Image(texture: Texture2D, onComplete:(base64image: string) => void, onError?:(message: string) => void, outputFormat: string = 'png') {
let data = texture.image.data;
if(data instanceof HTMLImageElement){
let url = texture.image.nativeUrl;
if(url.length > 0){
const img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = () => {
Expand All @@ -21,9 +21,9 @@ export class ImageUtils {
img.onerror = () => {
onError?.('error occurs during texture loading');
}
img.src = data.src;
img.src = url;
} else {
onError?.('texture must be HTMLImageDocument');
onError?.(`texture's image.nativeUrl is empty`);
}
}

Expand Down

0 comments on commit 92eafca

Please sign in to comment.