I'm experimenting with tiling a fullscreen image (480x320px ARGB
bitmap) with a square image (160x160px ARGB bitmap). My initial
implementation was naive:

public void render(Canvas canvas) {
        final int size = tile.getWidth();
        final int w = canvas.getWidth();
        final int h = canvas.getHeight();
                for (int y = 0; y < h; y += size) {
                        for (int x = 0; x < w; x += size) {
                        canvas.drawBitmap(tile, x, y, null);
                }
        }
}

Then I remembered that Paint supports a Shader, so I swapped this
implementation for something much more satisfying:

public void render(Canvas canvas) {
                canvas.drawPaint(paint);
}

Where paint is initialized outside this method with:

paint = new Paint();
paint.setShader(new BitmapShader(tile, Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT));

I expected that using a BitmapShader would be competitive with the
first implementation and probably slightly faster. But initial
benchmarking indicates that the first method is more than twice as
fast (almost 3x as fast if PorterDuff.Mode.SRC is used for both). I
found that surprising.

Is there a good reason that the BitmapShader is necessarily much
slower, or does it point to a deficiency in its implementation?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to