- import android.app.Activity;
- 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.PorterDuff;
- import android.graphics.PorterDuff.Mode;
- import android.graphics.PorterDuffXfermode;
- import android.graphics.Rect;
- import android.graphics.RectF;
- import android.graphics.drawable.Drawable;
- import android.os.Bundle;
- import android.view.View;
-
- public class MyCanvasActivity extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(new ImageEffect(this));
- }
-
- class ImageEffect extends View{
- Paint paint;
- public ImageEffect(Context context){
- super(context);
- paint= new Paint();
- paint.setAntiAlias(true);
- paint.setShadowLayer(5f, 5.0f, 5.0f, Color.BLACK);
- paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
-
- }
- public void onDraw(Canvas canvas){
- super.onDraw(canvas);
- int posX = 20;
- int posY = 50;
- int PicWidth,PicHeight;
-
- Drawable drawable = getResources().getDrawable(R.drawable.pic);
- Drawable dbe = getResources().getDrawable(R.drawable.pic).mutate();
- Drawable drawTest = getResources().getDrawable(R.drawable.pic);
- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pic);
- PicWidth = drawable.getIntrinsicWidth();
- PicHeight = drawable.getIntrinsicHeight();
-
- drawTest.setBounds(posX, (2 * posY) + PicHeight, posX + PicWidth, (2 * posY) + 2 * PicHeight );
- drawable.setBounds(posX,posY,posX+PicWidth,posY+PicHeight);
- dbe.setBounds(0, 0, PicWidth, PicHeight);
-
- canvas.drawColor(Color.WHITE);
- canvas.save(Canvas.MATRIX_SAVE_FLAG);
- dbe.setColorFilter(0x7f000000,PorterDuff.Mode.SRC_IN);
- canvas.translate(posX + (int)(0.9 * PicWidth/2), posY + PicHeight/2);
- canvas.skew(-0.9F, 0.0F);
- canvas.scale(1.0f, 0.5f);
- dbe.draw(canvas);
- drawable.clearColorFilter();
- canvas.restore();
-
- canvas.save(Canvas.MATRIX_SAVE_FLAG);
- drawable.draw(canvas);
- canvas.restore();
-
-
- canvas.save(Canvas.MATRIX_SAVE_FLAG);
- drawTest.draw(canvas);
- canvas.restore();
-
-
- Rect rect = new Rect(2*posX + PicWidth + 3, 2*posY + PicHeight + 3, 2*posX + 2*PicWidth - 2, 2*posY + 2*PicHeight - 2);
-
-
- RectF rectF = new RectF(rect);
- canvas.drawRoundRect(rectF, 10f, 10f, paint);
- canvas.drawBitmap(bmp, 2*posX + PicWidth, 2*posY + PicHeight, null);
- canvas.restore();
- }
- }
- }
posted on
2013-08-16 13:59
創丗仼
阅读(
3426)
评论()
编辑
收藏
举报