TextureResourceCanvas dimensions not accurate

I have the following code to render “pixels” to a canvas texture:

local texture = graphics.newTexture({ type = ‘canvas’, width = 3, height = 3 })

texture:draw(display.newRect(0, 0, 1, 1))

texture:draw(display.newRect(1, 0, 1, 1))

texture:draw(display.newRect(2, 0, 1, 1))

texture:draw(display.newRect(0, 1, 1, 1))

texture:draw(display.newRect(2, 1, 1, 1))

texture:draw(display.newRect(0, 2, 1, 1))

texture:draw(display.newRect(1, 2, 1, 1))

texture:draw(display.newRect(2, 2, 1, 1))

texture:invalidate()

local rect = display.newImageRect(texture.filename, texture.baseDir, 3, 3)

rect:scale(5, 5)

rect:translate(display.contentCenterX, display.contentCenterY)

You can see that my Rects are clearly within the bounds of the texture’s dimensions. However, if I render it like above, I can only see half of the image. Only if I increase the dimensions of my texture, I can see the full picture.

Is this is a bug?

Have you tried restricting your initial  **newTexture() **sizes to powers-of-two?

I’m not really familiar with this feature (only used once or twice), but anything texture seems like it would want to be a power-of-two.

I look forward to other answers and the results of your own research. 

Cheers,

Ed

It sounds like a mismatch between your coordinates and the texture’s anchor values. Try adjusting one or the other.

Also, if your code will generally look like what you’ve listed, a memory bitmap might be more convenient.

Awesome, that is exactly what I needed. It’s important to know though that the top-right coordinate of the memory bitmap is (1, 1) rather than (0, 0). Thanks, StarCrunch!

Have you tried restricting your initial  **newTexture() **sizes to powers-of-two?

I’m not really familiar with this feature (only used once or twice), but anything texture seems like it would want to be a power-of-two.

I look forward to other answers and the results of your own research. 

Cheers,

Ed

It sounds like a mismatch between your coordinates and the texture’s anchor values. Try adjusting one or the other.

Also, if your code will generally look like what you’ve listed, a memory bitmap might be more convenient.

Awesome, that is exactly what I needed. It’s important to know though that the top-right coordinate of the memory bitmap is (1, 1) rather than (0, 0). Thanks, StarCrunch!