Android Color Rendering (quad) Bitmapshader bitmap rendering

Source: Internet
Author: User

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

Android Color processing (quad) Bitmapshader bitmap rendering

Public Bitmapshader(Bitmap bitmap,shader.tilemode tilex,shader.tilemode Tiley)

Call this method to produce a renderer (Shader) that draws a bitmap.

bitmap bitmaps used within the renderer

Tilex   The tiling mode for x to draw the bitmap in. X-Direction renderer tiling mode on bitmap

Tiley    The tiling mode for Y-draw the bitmap in. The Y-direction renderer tiling mode on the bitmap

Tilemode:

CLAMP : If the renderer exceeds the original boundary range, the range edge staining is copied.

REPEAT : Landscape and portrait Repeat renderer picture, tiled.

MIRROR : Horizontal and vertical duplicate renderer picture, this is not the same as the repeat repetition, he is tiled in a mirrored manner.

First Look at:

or directly on the code:

Mainactivity:

[Java]View PlainCopy
  1. Package com.tony.shader;
  2. Import Android.os.Bundle;
  3. Import android.app.Activity;
  4. Public class Mainactivity extends Activity {
  5. private Bitmapshaderview Shaderview;
  6. @Override
  7. protected void OnCreate (Bundle savedinstancestate) {
  8. super.oncreate (savedinstancestate);
  9. Shaderview = New Bitmapshaderview (this);
  10. Setcontentview (Shaderview);
  11. }
  12. }


Bitmapshaderview:

[Java]View PlainCopy
    1. Package com.tony.shader;
    2. Import Android.content.Context;
    3. Import Android.graphics.Bitmap;
    4. Import Android.graphics.BitmapShader;
    5. Import Android.graphics.Canvas;
    6. Import Android.graphics.Paint;
    7. Import Android.graphics.Shader;
    8. Import android.graphics.drawable.BitmapDrawable;
    9. Import android.graphics.drawable.ShapeDrawable;
    10. Import Android.graphics.drawable.shapes.OvalShape;
    11. Import Android.util.AttributeSet;
    12. Import Android.view.View;
    13. Public class Bitmapshaderview extends View {
    14. private Bitmapshader bitmapshader = null;
    15. private Bitmap Bitmap = null;
    16. Private Paint paint = null;
    17. private Shapedrawable shapedrawable = null;
    18. private int bitmapwidth = 0;
    19. private int bitmapheight = 0;
    20. Public Bitmapshaderview (context context) {
    21. super (context);
    22. //Get images
    23. Bitmap = ((bitmapdrawable) getresources (). getdrawable (R.drawable.cat))
    24. . Getbitmap ();
    25. Bitmapwidth = Bitmap.getwidth ();
    26. Bitmapheight = Bitmap.getheight ();
    27. //Construct renderer Bitmapshader
    28. Bitmapshader = New Bitmapshader (bitmap, shader.tilemode.mirror,shader.tilemode.repeat);
    29. }
    30. Public Bitmapshaderview (Context context,attributeset set) {
    31. Super (context, set);
    32. }
    33. @Override
    34. protected void OnDraw (canvas canvas) {
    35. //TODO auto-generated method stub
    36. Super.ondraw (canvas);
    37. //Crop the picture to an ellipse
    38. //Build Shapedrawable object and define shape as ellipse
    39. shapedrawable = New Shapedrawable (new OvalShape ());
    40. //Get brushes and set renderer
    41. Shapedrawable.getpaint (). Setshader (Bitmapshader);
    42. //Set display area
    43. Shapedrawable.setbounds ( 20,bitmapwidth-140,bitmapheight);
    44. //Draw shapedrawable
    45. Shapedrawable.draw (canvas);
    46. }
    47. }

Android Color Rendering (quad) Bitmapshader bitmap rendering

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.