• Android学习笔记进阶17之LinearGradient


    具体的看一下博文:Android学习笔记进阶15之Shader渲染

    1. package xiaosi.BitmapShader;  
    2.   
    3. import android.app.Activity;  
    4. import android.os.Bundle;  
    5.   
    6. public class BitmapShaderActivity extends Activity {  
    7.     /** Called when the activity is first created. */  
    8.     private BitmapShaders bitmapShaders = null;  
    9.     @Override  
    10.     public void onCreate(Bundle savedInstanceState) {  
    11.         super.onCreate(savedInstanceState);  
    12.           
    13.         bitmapShaders = new BitmapShaders(this);  
    14.         setContentView(bitmapShaders);  
    15.     }  
    16. }  


    BitmapShaders.Java

      1. package xiaosi.BitmapShader;  
      2.   
      3. import android.content.Context;  
      4. import android.graphics.Bitmap;  
      5. import android.graphics.BitmapShader;  
      6. import android.graphics.Canvas;  
      7. import android.graphics.Color;  
      8. import android.graphics.ComposeShader;  
      9. import android.graphics.LinearGradient;  
      10. import android.graphics.Paint;  
      11. import android.graphics.PorterDuff;  
      12. import android.graphics.RadialGradient;  
      13. import android.graphics.Shader;  
      14. import android.graphics.SweepGradient;  
      15. import android.graphics.drawable.BitmapDrawable;  
      16. import android.graphics.drawable.ShapeDrawable;  
      17. import android.graphics.drawable.shapes.OvalShape;  
      18. import android.view.View;  
      19.   
      20. public class BitmapShaders extends View  
      21. {  
      22.     private LinearGradient linearGradient = null;  
      23.     private ComposeShader composeShader = null;  
      24.     private SweepGradient sweepGradient = null;  
      25.     private RadialGradient radialGradient = null;  
      26.     private BitmapShader bitmapShader = null;  
      27.     private Bitmap bitmap = null;  
      28.     private Paint paint = null;  
      29.     private ShapeDrawable shapeDrawable = null;  
      30.     private int BitmapWidth = 0;  
      31.     private int BitmapHeight = 0;  
      32.   
      33.     public BitmapShaders(Context context)  
      34.     {  
      35.         super(context);  
      36.         // 得到图像  
      37.         bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.v))  
      38.                 .getBitmap();  
      39.         BitmapWidth = bitmap.getWidth();  
      40.         BitmapHeight = bitmap.getHeight();  
      41.         // 构造渲染器LinearGradient  
      42.         linearGradient = new LinearGradient(0, 0, 100, 100, new int[] {  
      43.                 Color.RED, Color.GREEN, Color.BLUE, Color.WHITE }, null,  
      44.                 Shader.TileMode.REPEAT);  
      45.         paint = new Paint();  
      46.     }  
      47.   
      48.     @Override  
      49.     protected void onDraw(Canvas canvas)  
      50.     {  
      51.         super.onDraw(canvas);  
      52.         paint.setShader(linearGradient);  
      53.         canvas.drawRect(20, 50, 320, 156, paint);  
      54.     }  
  • 相关阅读:
    Codeforces Round #352 (Div. 1) B. Robin Hood 二分
    Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
    Codeforces Round #352 (Div. 2) B. Different is Good 水题
    Codeforces Round #352 (Div. 2) A. Summer Camp 水题
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
    Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学
    Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/6722141.html
Copyright © 2020-2023  润新知