package com.example.cavis; import android.R.color; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.Path; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; @SuppressWarnings("deprecation") public class MyView extends View { private Paint paint; private Bitmap srcBitmap,dscBitmap; private int Height,Weigth; public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // TODO Auto-generated constructor stub paint = new Paint(Paint.ANTI_ALIAS_FLAG); srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ico_image); Weigth = srcBitmap.getWidth(); Height = srcBitmap.getHeight(); dscBitmap = Bitmap.createBitmap(Weigth, Height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dscBitmap); //canvas.drawRoundRect(new RectF(0, 40, Weigth, Height), 40, 40, paint);//四个圆角 //canvas.drawRoundRect(new RectF(0, -40, Weigth, Height), 40, 40, paint);//两个下圆角 canvas.drawRoundRect(new RectF(0, 0, Weigth, Height+40), 40, 40, paint);//两个上圆角 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(srcBitmap, 0, 0,paint); } public MyView(Context context, AttributeSet attrs) { this(context, attrs, 0); // TODO Auto-generated constructor stub } public MyView(Context context) { this(context, null); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub canvas.drawBitmap(dscBitmap, 0,0, null); } }
时间: 2024-12-16 09:15:41