[removed] Render PNG stored as Uint8Array onto Canvas element without Data URI

后端 未结 3 1519
面向向阳花
面向向阳花 2020-12-29 04:51

I\'m trying to render a PNG image that is stored in a javascript Uint8Array. The code that I originally tried was the following:

var imgByteStr         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 04:58

    If you already have a UInt8Array, you should consider using Blob and createObjectURL; createObjectURL allocates a special URL that allows the browser to access an internally created blob of binary data as though it were a file being loaded externally.

    Where it is supported, createObjectURL is an excellent alternative to huge data URIs. You may still need to fall back to use of data URIs in Opera, IE<10, and all but the most recent versions of mobile browsers.

    var myArray; //= your data in a UInt8Array
    var blob = new Blob([myArray], {'type': 'image/png'});
    var url = URL.createObjectURL(blob); //possibly `webkitURL` or another vendor prefix for old browsers.
    

提交回复
热议问题