package com.chaoran.entiry;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.widget.ImageView;

public class SelfImage extends ImageView {
	private Bitmap bitmap;
	private boolean isDrawBound;

	public Bitmap getBitmap() {
		return bitmap;
	}

	public void setBitmap(Bitmap bitmap) {
		if (this.bitmap != null) {
			setImageBitmap(null);
			this.bitmap.recycle();
			this.bitmap = null;
		}
		setImageBitmap(bitmap);
		this.bitmap = bitmap;
	}

	public SelfImage(Context context) {
		super(context);
	}

	public SelfImage(Context context, boolean isDrawBound) {
		super(context);
		this.isDrawBound = isDrawBound;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		if (isDrawBound) {
			Rect rec = canvas.getClipBounds();
			rec.bottom--;
			rec.right--;
			Paint paint = new Paint();
			paint.setColor(Color.RED);
			paint.setStyle(Paint.Style.STROKE);
			paint.setStrokeWidth(5);
			canvas.drawRect(rec, paint);
		}
	}
}
