Android Color Rendering (eight) sweepgradient scan/gradient rendering

Source: Internet
Author: User

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

Directory (?) [+]

Android color Processing (eight) sweepgradient scan/gradient rendering

Why is it called scan rendering? I believe everyone has seen the effect of radar scanning, especially in security software.

public sweepgradient(float cx, float CY, int[] colors, float[] positions) Parameters:
Cx Render Center point X coordinate
Cy Render Center Y-point coordinates
Colors A color array that is rendered around the center, with at least two color values
Positions The color array relative to the position, nullable, NULL, nullable, and the color evenly spaced along the gradient line

public sweepgradient(float cx, float CY, int color0, int color1) Parameters:
Cx Render Center point X coordinate
Cy Render Center point Y coordinate
Color0 Start Render Color
Color1 End Render Color

:

Code:

Mainactivity:

[Java]View PlainCopy
  1. Package com.tony.testshader;
  2. Import Android.os.Bundle;
  3. Import android.app.Activity;
  4. Import Android.graphics.Bitmap;
  5. Import Android.graphics.BitmapFactory;
  6. Import Android.view.Menu;
  7. Import Android.widget.SeekBar;
  8. Import Android.widget.SeekBar.OnSeekBarChangeListener;
  9. Public class Mainactivity extends Activity implements onseekbarchangelistener{
  10. private Sweepgradientview Sweepgradientview;
  11. @Override
  12. protected void OnCreate (Bundle savedinstancestate) {
  13. super.oncreate (savedinstancestate);
  14. Sweepgradientview = new Sweepgradientview (mainactivity.   this);
  15. Setcontentview (Sweepgradientview);
  16. }
  17. @Override
  18. Public Boolean oncreateoptionsmenu (Menu menu) {
  19. Getmenuinflater (). Inflate (R.menu.main, menu);
  20. return true;
  21. }
  22. }

Sweepgradientview:

  1. Package com.tony.testshader;
  2. Import Android.content.Context;
  3. Import Android.graphics.Canvas;
  4. Import Android.graphics.Color;
  5. Import Android.graphics.Paint;
  6. Import Android.graphics.Shader;
  7. Import android.graphics.SweepGradient;
  8. Import Android.util.AttributeSet;
  9. Import Android.view.View;
  10. Public class Sweepgradientview extends View {
  11. Paint mpaint = null;
  12. //Gradient rendering
  13. Shader msweepgradient = null;
  14. Public Sweepgradientview (context context) {
  15. super (context);
  16. //Create Sweepgradient Object
  17. //First, second parameter center coordinate
  18. //parameters are the same as linear rendering
  19. Msweepgradient = New Sweepgradient (The new int[] {color.cyan,color.dkgray,color.gray, Color.ltgray,color.magenta,
  20. Color.green,color.transparent, color.blue}, null);
  21. Mpaint = new Paint ();
  22. }
  23. Public Sweepgradientview (context context, AttributeSet attrs) {
  24. Super (context, attrs);
  25. }
  26. @Override
  27. protected void OnDraw (canvas canvas) {
  28. Super.ondraw (canvas);
  29. //Draw gradient gradient
  30. Mpaint.setshader (msweepgradient);
  31. Canvas.drawcircle ( mpaint);
  32. }
  33. }

Android Color Rendering (eight) sweepgradient scan/gradient rendering

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.