Android Shader renderer: Bitmapshader

Source: Internet
Author: User
Tags repetition

Shader

Bitmapshader, the Shader family specializes in image rendering.


Construction Method:

Bitmapshader (Bitmap Bitmaptilemode tilextilemode Tiley)

Bitmap: Original

Tiles are literal , tiles. The tilemode here can be seen as a pattern of paving.

Tilex, pattern of tiley:x/y direction paving


public enum Tilemode {     CLAMP   (0),    REPEAT  (1),    MIRROR  (2);    Tilemode (int nativeint) {        this.nativeint = nativeint;    }    final int nativeint;}
CLAMP: If the original bounds (that is, the border of the artwork) is exceeded, the color on the repeating edge

REPEAT: Repeat Bitmap

MIRROR: Repeat bitmap, unlike repeat, it is a mirror repetition, namely: reverse repetition


Cases:

public class Bitmapshaderview extends View {    private bitmapshader mbitmapshader;    Private shapedrawable mshapedrawable;    Public Bitmapshaderview (context context, Bitmap Bitmap) {        super (context);        Mbitmapshader = new Bitmapshader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);        mshapedrawable = new Shapedrawable (new OvalShape ());        Mshapedrawable.getpaint (). Setshader (Mbitmapshader);//        mshapedrawable.setbounds (0, 0, bitmap.getwidth (), Bitmap.getheight ()); Original size        mshapedrawable.setbounds (0, 0, bitmap.getwidth () * 2, Bitmap.getheight () * 2);    }    @Override    protected void OnDraw (canvas canvas) {        super.ondraw (canvas);        Canvas.drawcolor (Color.cyan);        Mshapedrawable.draw (canvas);}    }
In the activity, Setcontentview (new Bitmapshaderview (context, bitmap));

Original

X and y edges repeat


Change: Mbitmapshader = new Bitmapshader (bitmap, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT);

Effect

X-direction Mirror Repeat, y-direction repeat


Change: Mbitmapshader = new Bitmapshader (bitmap, Shader.TileMode.REPEAT, Shader.TileMode.MIRROR);
Effect:

Repeat in x direction, mirror repeat in y direction




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Shader renderer: Bitmapshader

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.