How to create a picture using ImageData?


How to create a picture using ImageData? what’s imageType?

initWithImageFile: function (strPath, imageType) {
    var data = cc.FileUtils.getInstance().getFileData(strPath, "rb");
    var size = data.length;
    if (data != null && data.length > 0)
        return this.initWithImageData(data, data.length, imageType);
    return false;


The doc ( says “@param {Number} imageType the type of image, now only support tow types.”. I assume “tow” = “two”, but I don’t think that info is up to date, considering what’s done later in the code.

It seems you can pass the following imageType values: cc.FMT_PNG, cc.FMT_JPG, cc.FMT_TIFF, cc.FMT_RAWDATA. If the values is different from those, it assumes it may be a PNG or TIFF file buffer.




Sorry, I can’t read Chinese.
If you can’t get it to work, maybe post the exact error message you get, show your code, or maybe try Canvas mode if you’re in WebGL mode.

I haven’t tried using the initWithImageData function directly, but the initWithImageFile function worked fine for me.