Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class V extends View {
- Bitmap bitmap;
- Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
- Matrix matrix = new Matrix();
- Path path = new Path();
- public V(Context context) {
- super(context);
- bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chrome);
- paint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
- path.moveTo(8, 5);
- path.cubicTo(11, 0, 20, 8, 8, 14);
- path.cubicTo(-4, 8, 5, 0, 8, 5);
- float scale = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 16f;
- matrix.setScale(scale, scale);
- path.transform(matrix);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- RectF src = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
- RectF dst = new RectF(0, 0, w, h);
- matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.concat(matrix);
- canvas.drawPath(path, paint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement