Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class V extends View {
- Bitmap bm;
- Matrix matrix = new Matrix();
- Matrix m0 = new Matrix();
- Matrix m1 = new Matrix();
- public V(Context context) {
- super(context);
- bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.test);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- float cx = w / 2f;
- float cy = h / 2f;
- float bw = bm.getWidth();
- float bh = bm.getHeight();
- m0.postTranslate(cx - bw / 2f, cy - bh / 2f);
- matrix = m0;
- m1.set(m0);
- m1.postRotate(90, cx, cy);
- m1.postScale(bw / bh ,bh / bw, cx, cy);
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- matrix = matrix == m0? m1 : m0;
- invalidate();
- return false;
- }
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.drawBitmap(bm, matrix, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement