Advertisement
Guest User

Untitled

a guest
May 4th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. class V extends View {
  2.  
  3. Bitmap bitmap;
  4. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  5. Matrix matrix = new Matrix();
  6. Path path = new Path();
  7.  
  8. public V(Context context) {
  9. super(context);
  10. bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chrome);
  11. paint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  12.  
  13. path.moveTo(8, 5);
  14. path.cubicTo(11, 0, 20, 8, 8, 14);
  15. path.cubicTo(-4, 8, 5, 0, 8, 5);
  16. float scale = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 16f;
  17. matrix.setScale(scale, scale);
  18. path.transform(matrix);
  19. }
  20.  
  21. @Override
  22. protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  23. RectF src = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
  24. RectF dst = new RectF(0, 0, w, h);
  25. matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
  26. }
  27.  
  28. @Override
  29. protected void onDraw(Canvas canvas) {
  30. canvas.concat(matrix);
  31. canvas.drawPath(path, paint);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement