cocos creator 怎么获取图片像素值

在native上怎么获取,我获取的时候都报错
模拟器上我用的textureRender 方式,会报错

                 var rt = dataContainer
                if (!rt){
                    rt = new cc.RenderTexture()
                    rt.initWithSize(tex.width, tex.height)
                    rt.drawTextureAt(tex, 0, 0)
                    _textureIdMapDataContainer[tex.getId()] = rt
                }
    
               // data就是这个texture的rgba值数组
                if (spriteFrame.isRotated()) {
                    data = rt.readPixels(null, rect.x + posInRect.y, rect.y + posInRect.x, 1, 1)
                    //cc.log(type + "--", "data", data, rect.x + posInRect.y, rect.y + posInRect.x)
                }
                else {
                    data = rt.readPixels(null, rect.x + posInRect.x, rect.y + rect.height - posInRect.y, 1, 1)
                    //cc.log(type + "--", "data", data, rect.x + posInRect.x, rect.y + rect.height - posInRect.y)
                }

Simulator: [ERROR] (/Users/nantas/fireball-x/cocos2d-x-lite_21/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp, 1888): glReadPixels((GLint)arg0 , (GLint)arg1 , (GLsizei)arg2 , (GLsizei)arg3 , (GLenum)arg4 , (GLenum)arg5 , (GLvoid*)arg6 ); GL error 0x506: GL_INVALID_FRAMEBUFFER_OPERATION
[ERROR] Failed to invoke JSB_glReadPixels, location: /Users/nantas/fireball-x/cocos2d-x-lite_21/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp:1892
at HTMLElement.print-simulator-log (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/builtin/scene/panel/messages/scene.js:1:1669)
at Object.e._dispatch (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor-framework/lib/renderer/panel.js:1:1941)
at EventEmitter.o.on.s (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor-framework/lib/renderer/ipc.js:1:2921)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)

cocos里面也有getImageData嘛?

这个是h5接口,原生要用rdt->newImage()->getData()

先预生成多边形,然后用 cc.Intersection.pointInPolygon 判断如何

carera.renderTexture = texture //texture一像素即可
carera.render() //需要检测的图片设置group和camera对应
var data =texture.readPixels()
if(data[0] !=0){
//点击非透明
}

我用了你的组件但是读出来的像素都是0 怎么破
报了一个这样的警告[.Offscreen-For-WebGL-00000248743FB0B0]GL ERROR :GL_INVALID_FRAMEBUFFER_OPERATION : glReadPixels: framebuffer incomplete

什么平台?

我的也是读出全零,而且报那个错,不知道怎么解决

mark

同样的问题,请问楼主解决了吗

没有,官方都没有给出一个可行的解决方案

同样的问题,现在还没有方案么?

上面已经有人给出了方案

你好 您是怎么用cocos c++实现的啊 能详细说一下嘛

这里判断选中了那一块tile,可以使用世界坐标转换到tiledmap坐标来判断tile里面设置的属性,
斜45度的算法好像论坛里面是有的

你好 你们解决了吗

你们解决了吗

你好,请问最后怎么解决的