spriteFrame 如何获得像素点颜色

通过对Graphics进行截图,截完如下面有白边的B,然后通过 spriteFrame.setRect(cc.rect(data.minX,data.minY,w,h)); 变成上面没白边的B,如何获取spriteFrame的像素点呢,非常感谢

自己顶一下!!!

第一次提问,大佬们回复一下,找了好多天了

目前只知道通过 renderTexture.readPixels(); 获得,但不知道怎么通过spriteFrame通过图片的像素点

你的graphics再绘制的时候肯定能获取到绘制过程中的点撒,
就检查你的每一个点的最大值和最小值 停下了之后就能确定一个矩形了撒 你就晓得了嘛

我尝试过通过
let texture = new cc.RenderTexture();
texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height);
this.drawCamera.targetTexture = texture;
this.texture = texture;

drawCamera.render();
let data = texture.readPixels();

又获取到了有空白区域的图片 像素点

我就是通过确定一个矩形,才通过setRect得到的结果,可怎么得到这个地方的像素点呢?谢谢

别沉呀!!!

graphics 移动你是通过 注册触摸事件来绘制的吧
touchMove事件里面你能获取到你的触摸点撒,,然后就能转换为你贴图的上的点了啊

你的意思是 记录每个触摸的点 x、y?
可我的需求是 不管画多大 都只用100 * 100的图片来缩小,然后再获取100 * 100的像素点。

用这种形式就能获取到像素颜色
cc.loader.getRes(‘hhh.png’,function(err,texture){
var rt = new cc.RenderTexture()
rt.initWithSize(texture.width, texture.height)
rt.drawTextureAt(texture, 0, 0)
var data = rt.readPixels()
})

用这种获取到的像素点颜色都为0
var spriteFrame = this.sprite.spriteFrame
var texture = spriteFrame.getTexture()
var rt = new cc.RenderTexture()
rt.initWithSize(texture.width, texture.height)
rt.drawTextureAt(texture, 0, 0)
var data = rt.readPixels()

2赞

截图后已经能获得到 spriteFrame,并可以显示,就是不知如何获得显示的像素点颜色