Advertisement
minafaw3

CircleDrawable

Jan 17th, 2017
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Android.App;
  7. using Android.Content;
  8. using Android.OS;
  9. using Android.Runtime;
  10. using Android.Views;
  11. using Android.Widget;
  12. using Android.Graphics.Drawables;
  13. using Android.Graphics;
  14.  
  15. namespace DSP.Droid
  16. {
  17. public class CircleDrawable : Drawable
  18. {
  19. Bitmap bmp;
  20. BitmapShader bmpShader;
  21. Paint paint;
  22. RectF oval;
  23.  
  24. public CircleDrawable(Bitmap bmp)
  25. {
  26. this.bmp = bmp;
  27. this.bmpShader = new BitmapShader(bmp, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
  28. this.paint = new Paint() { AntiAlias = true };
  29. this.paint.SetShader(bmpShader);
  30. this.oval = new RectF();
  31. }
  32.  
  33. public override void Draw(Canvas canvas)
  34. {
  35. canvas.DrawOval(oval, paint);
  36. }
  37.  
  38. protected override void OnBoundsChange(Rect bounds)
  39. {
  40. base.OnBoundsChange(bounds);
  41. oval.Set(0, 0, bounds.Width(), bounds.Height());
  42. }
  43.  
  44. public override int IntrinsicWidth
  45. {
  46. get
  47. {
  48. return bmp.Width;
  49. }
  50. }
  51.  
  52. public override int IntrinsicHeight
  53. {
  54. get
  55. {
  56. return bmp.Height;
  57. }
  58. }
  59.  
  60. public override void SetAlpha(int alpha)
  61. {
  62.  
  63. }
  64.  
  65. public override int Opacity
  66. {
  67. get
  68. {
  69. return (int)Format.Opaque;
  70. }
  71. }
  72.  
  73. public override void SetColorFilter(ColorFilter cf)
  74. {
  75.  
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement