Canvas
canvas.drawBitmap(bitmap, 0f, 0f, paint)
clip
canvas.clipRect(0.25f * bitmap.width, 0f, 0.75f * bitmap.width, bitmap.height.toFloat())
canvas.drawBitmap(bitmap, 0f, 0f, paint)
translate, rotate
canvas.translate(300f, 0f)
canvas.rotate(30f)
rotate clip
canvas.rotate(degree, centerX, centerY) //旋轉(zhuǎn)canvas
canvas.clipRect(0f, 0f, centerX, vHeight) // clip,獲得一個(gè)斜切的繪制區(qū)域
canvas.rotate(-degree, centerX, centerY) // 旋轉(zhuǎn)會(huì)畫布床蜘,一遍后面水品繪制bitmap
canvas.drawBitmap(bitmap, centerX - bWidth / 2, centerY - bHeight / 2, paint)
scale
canvas.scale(1f, 2f, centerX, centerY)
canvas.drawBitmap(bitmap, centerX - bWidth / 2, centerY - bHeight / 2, paint)
skew
Camera rotate
canvas.translate(centerX, centerY)
camera.rotateX(60f)
camera.applyToCanvas(canvas)
canvas.translate(-centerX, -centerY)
canvas.drawBitmap(bitmap, centerX - bWidth / 2, centerY - bHeight / 2, paint)
綜合應(yīng)用
核心代碼
canvas.save()
canvas.save()
camera.save()
canvas.translate(centerX, centerY)
canvas.rotate(degreeZ)
canvas.clipRect(-centerX, centerY, 0f, -centerY) // 旋轉(zhuǎn)之后 clip 得到一個(gè) 斜切的可繪制區(qū)域
camera.rotateY((leftDegreeY))
camera.applyToCanvas(canvas)
canvas.rotate(-degreeZ) // 反方向旋轉(zhuǎn)回來辙培,以便bitmap能夠水品繪制
canvas.translate(-centerX, -centerY)
canvas.drawBitmap(bitmap, x, y, paint);
canvas.restore()
camera.restore()