[FIXED] Wrong rgb pixel content from another frame

Hello there o/

I want to go through all frames and read the pixel contents of all merged layers.

For this I made the following code:
got object with all frames

local frames = app.sprite.frames

thru the circle get next frame:

local frames = app.sprite.frames
	for fNum = 1, #frames, 1 do
	local frame = app.sprite.frames[fNum]

Next I get the image through the frame sprite

	local image = Image(frame.sprite)
	for it in image: pixels() do
			local pixelValue = it()
			local pc = app.pixelColor
			local r = pc.rgbaR(pixelValue)
			local g = pc.rgbaG(pixelValue)
			local b = pc.rgbaB(pixelValue)

The RGB data got fine, but there is a problem.
This data is always only from the first frame, that is, it is always the same.

And I can’t figure out whether I’m not getting the Image() object correctly or whether there’s something wrong here.

If you output debug data to the console, you can see that the pointers to the sprite object are different, but the RGB data is the same:

print(frame.frameNumber, frame.duration, frame.sprite)

Thank you very much in advance

Fortunately, I was able to figure out what the reason was, I hope this information will be useful to someone else.

The problem was that when creating an Image based on a Sprite, only the 1st frame is always taken (as stated in the description).
To work with subsequent frames, you need to create a new Image and copy to it using drawSprite.

		local frame = app.sprite.frames[fNum]
		local image = Image(frame.sprite.width, frame.sprite.height)
		image:drawSprite(frame.sprite, fNum)

Where fNum is frame number.

1 Like