安卓:在画布平铺位图平铺、位图、画布

由网友(還是会离开)分享简介:我想创建一个方格纸放眼位图,我通过一个Canvas绘图,并试图找出做到这一点的最好办法。I would like to create a 'graph paper' look to the Bitmap I am drawing via a Canvas, and trying to figure out the b...

我想创建一个方格纸放眼位图,我通过一个Canvas绘图,并试图找出做到这一点的最好办法。

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.

我无法传递包含方格纸背景画布构造一个源位图,因为我通过.lockCanvas越来越画布在SurfaceView()调用。

I can't pass a source Bitmap containing the graph paper background to the Canvas constructor, as I am getting the Canvas in a SurfaceView via the .lockCanvas() call.

一些解决方案,我已经试过:

Some solutions I've tried:

我已经试过落实在我的SurfaceView的主题这个解决方案。运行(),但是当BitmapDrawable转换为位图的问题,我认为是......它失去平铺属性。

I've tried implementing this solution in my SurfaceView's Thread.run(), but the issue I believe is when the BitmapDrawable is converted to a Bitmap... it loses the tiling properties.

画布= mSurfaceHolder.lockCanvas(空); BitmapDrawable TileMe =新BitmapDrawable(BitmapFactory.de codeResource(getResources(),R.drawable.editor_graph)); TileMe.setTileModeX(Shader.TileMode.REPEAT); TileMe.setTileModeY(Shader.TileMode.REPEAT);

canvas = mSurfaceHolder.lockCanvas(null); BitmapDrawable TileMe = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.editor_graph)); TileMe.setTileModeX(Shader.TileMode.REPEAT); TileMe.setTileModeY(Shader.TileMode.REPEAT);

位图B = TileMe.getBitmap(); canvas.drawBitmap(B,0,0,NULL);

Bitmap b = TileMe.getBitmap(); canvas.drawBitmap(b, 0, 0, null);

如果我使用Canvas.drawBitmap方法,它的目的地RectF作为参数,它看起来像将被平铺,以填补RectF位图......但我怎么申报RectF可靠,填补了整个景区?

If I use the Canvas.drawBitmap method that takes a destination RectF as a parameter, it looks like the bitmap will be tiled to fill the RectF... but how do I declare a RectF reliably that fills the entire view area?

任何想法如何实现这一目标?

Any ideas how to achieve this?

谢谢, 保

推荐答案

您有两个简单的解决办法:

You have two easy solutions:

要么使用一个BitmapDrawable的,而是提取位图,只需拨打BitmapDrawable.draw(画布)。不要忘记设置可绘制的边界,以填补你的绘图区域。 创建一个BitmapShader一个画画它的矩形(这基本上是BitmapDrawable呢)。
阅读全文

相关推荐

最新文章