public void draw(Canvas canvas) { var boundRect = canvas.getTotalMatrix().mapRect(this.logicalRect); var bounds = boundRect.withDevicePixelRatio(this.devicePixelRatio); D.assert(() => { var boundsInPixel = boundRect.roundOutScale(this.devicePixelRatio); var textureWidth = Mathf.CeilToInt(boundsInPixel.width); var textureHeight = Mathf.CeilToInt(boundsInPixel.height); //it is possible that there is a minor difference between the bound size and the image size (1 pixel at //most) due to the roundOut operation when calculating the bounds if the elements in the canvas transform //is not all integer D.assert(Mathf.Abs(this.image.width - textureWidth) <= 1); D.assert(Mathf.Abs(this.image.height - textureHeight) <= 1); return(true); }); canvas.save(); try { canvas.resetMatrix(); canvas.drawImage(this.image, bounds.topLeft, new Paint()); } finally { canvas.restore(); } }
public void draw(Canvas canvas) { var bounds = canvas.getTotalMatrix().mapRect(this.logicalRect).roundOut(this.devicePixelRatio); D.assert(() => { var textureWidth = Mathf.CeilToInt(bounds.width * this.devicePixelRatio); var textureHeight = Mathf.CeilToInt(bounds.height * this.devicePixelRatio); D.assert(this.image.width == textureWidth); D.assert(this.image.height == textureHeight); return(true); }); canvas.save(); try { canvas.resetMatrix(); canvas.drawImage(this.image, bounds.topLeft, new Paint()); } finally { canvas.restore(); } }