Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class V extends View {
  2.  
  3. Bitmap bm;
  4. Matrix matrix = new Matrix();
  5. Matrix m0 = new Matrix();
  6. Matrix m1 = new Matrix();
  7.  
  8. public V(Context context) {
  9. super(context);
  10. bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.test);
  11.  
  12. }
  13.  
  14. @Override
  15. protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  16. float cx = w / 2f;
  17. float cy = h / 2f;
  18. float bw = bm.getWidth();
  19. float bh = bm.getHeight();
  20. m0.postTranslate(cx - bw / 2f, cy - bh / 2f);
  21. matrix = m0;
  22.  
  23. m1.set(m0);
  24. m1.postRotate(90, cx, cy);
  25. m1.postScale(bw / bh ,bh / bw, cx, cy);
  26. }
  27.  
  28. @Override
  29. public boolean onTouchEvent(MotionEvent event) {
  30. matrix = matrix == m0? m1 : m0;
  31. invalidate();
  32. return false;
  33. }
  34.  
  35. @Override
  36. protected void onDraw(Canvas canvas) {
  37. canvas.drawBitmap(bm, matrix, null);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement