Android學習筆記進階17之LinearGradient

來源:互聯網
上載者:User

具體的看一下博文:Android學習筆記進階15之Shader渲染

 

package xiaosi.BitmapShader;</p><p>import android.app.Activity;<br />import android.os.Bundle;</p><p>public class BitmapShaderActivity extends Activity {<br /> /** Called when the activity is first created. */<br />private BitmapShaders bitmapShaders = null;<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);</p><p> bitmapShaders = new BitmapShaders(this);<br /> setContentView(bitmapShaders);<br /> }<br />}

BitmapShaders.java

package xiaosi.BitmapShader;</p><p>import android.content.Context;<br />import android.graphics.Bitmap;<br />import android.graphics.BitmapShader;<br />import android.graphics.Canvas;<br />import android.graphics.Color;<br />import android.graphics.ComposeShader;<br />import android.graphics.LinearGradient;<br />import android.graphics.Paint;<br />import android.graphics.PorterDuff;<br />import android.graphics.RadialGradient;<br />import android.graphics.Shader;<br />import android.graphics.SweepGradient;<br />import android.graphics.drawable.BitmapDrawable;<br />import android.graphics.drawable.ShapeDrawable;<br />import android.graphics.drawable.shapes.OvalShape;<br />import android.view.View;</p><p>public class BitmapShaders extends View<br />{<br />private LinearGradient linearGradient = null;<br />private ComposeShader composeShader = null;<br />private SweepGradient sweepGradient = null;<br />private RadialGradient radialGradient = null;<br />private BitmapShader bitmapShader = null;<br />private Bitmap bitmap = null;<br />private Paint paint = null;<br />private ShapeDrawable shapeDrawable = null;<br />private int BitmapWidth = 0;<br />private int BitmapHeight = 0;</p><p>public BitmapShaders(Context context)<br />{<br />super(context);<br />// 得到映像<br />bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.v))<br />.getBitmap();<br />BitmapWidth = bitmap.getWidth();<br />BitmapHeight = bitmap.getHeight();<br />// 構造渲染器LinearGradient<br />linearGradient = new LinearGradient(0, 0, 100, 100, new int[] {<br />Color.RED, Color.GREEN, Color.BLUE, Color.WHITE }, null,<br />Shader.TileMode.REPEAT);<br />paint = new Paint();<br />}</p><p>@Override<br />protected void onDraw(Canvas canvas)<br />{<br />super.onDraw(canvas);<br />paint.setShader(linearGradient);<br />canvas.drawRect(20, 50, 320, 156, paint);<br />}<br />}<br />

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.