Tiling a Bitmap on a Canvas

后端 未结 2 1659
鱼传尺愫
鱼传尺愫 2021-02-08 05:36

I would like to create a \'graph paper\' look to the Bitmap I am drawing via a Canvas, and trying to figure out the best way to do this.

I can\'t pass a source Bitmap co

2条回答
  •  孤城傲影
    2021-02-08 05:54

    I'm sure there is a way to get a tiled effect using a SurfaceView. Unfortunately, it looks like you can't use the BitmapDrawable with a canvas. So you would probably have to implement you own custom tiling method by creating your own series of Rect's on the Canvas and drawing a scaled bitmap to each one.

    It honestly wouldn't be that hard. Just get the width/height of the view, and create an array of Rect's based on this data that you will draw the Bitmap to.

    Alternatively, if you don't need to make modifications to the actual tiled background on the fly, just draw it as a background and draw the SurfaceView on top of it. That post you linked provided multiple solutions to tiling a BitmapDrawable that you could implement.

提交回复
热议问题