简体   繁体   中英

How to draw bitmap over already drawn canvas

val canvas = inputSurface.lockCanvas(null)
try {
    val source = Rect(200, 200, 400, 400)
    canvas.drawBitmap(watermark, null, source, null)
   currentFrame.draw(canvas)
} finally {
    inputSurface.unlockCanvasAndPost(canvas)
}

Here i am trying to draw bitmap(watermark) over canvas created from Surface. But bitmap(watermark) draws below the canvas created from Surface

This happens because you are first drawing the bitmap and the frame. By switching the drawing order you should see the watermark

    val canvas = inputSurface.lockCanvas(null)
    try {
        //First draw the frame
        currentFrame.draw(canvas)

        val source = Rect(200, 200, 400, 400)
        //Then draw the bitmap watermark
        canvas.drawBitmap(watermark, null, source, null)
    } finally {
        inputSurface.unlockCanvasAndPost(canvas)
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM