I am using assetManager.parser.parse() to parse binary array of jpg file.
Following function works for web.
If I write the binary to a file in native and pass the file path into assetManager.parser.parse(), it works also.
testLoadJpg() {
const blob = new Blob([global.gs_testBinary]);
let filePath = “”;
if (sys.isNative) {
filePath = FileUtil.gsp_writeFile(“test.jpg”, global.gs_testBinary);
}
// var base64String = btoa(String.fromCharCode.apply(null, global.gs_testBinary));
// base64String = 'data:image/jpeg;base64,' + base64String;
// console.log(base64String)
assetManager.parser.parse("test.jpg", sys.isBrowser ? blob : global.gs_testBinary, ".jpg" , null, (err, img1)=>{
//create the node with the image
const spriteNode = new CoreNode();
const spf = SpriteFrame.createWithImage(img1);
spriteNode.addComponent(Sprite);
const sprite = spriteNode.getComponent(Sprite);
sprite.spriteFrame =spf;
global.gs_stage[gs_popup_stage].addChild(spriteNode);
});
}
But I want to pass Uint8Array directly into assetManager.parser.parse() in native.
Please help me!
@zzf_Cocos Thank you for your support.
That works well, but my Uint8Array is as same as raw jpg file while this._buffer in this code is uncompressed Uint8Array for RGBA channel.
How can I use Uint8Array of raw jpg file?
You need to create a texture resource from the unit8Array first, using native.saveImageData to complete it, and then load the saved texture from the device through assetManager.loadRemote.