setImageMatrix , Drawable ( ):
class CropDrawable extends BitmapDrawable {
private Rect mSrc;
private RectF mDst;
public CropDrawable(Bitmap b, int left, int top, int right, int bottom) {
super(b);
mSrc = new Rect(left, top, right, bottom);
mDst = new RectF(0, 0, right - left, bottom - top);
}
@Override
public void draw(Canvas canvas) {
canvas.drawBitmap(getBitmap(), mSrc, mDst, null);
}
@Override
public int getIntrinsicWidth() {
return mSrc.width();
}
@Override
public int getIntrinsicHeight() {
return mSrc.height();
}
}
:
ImageView iv = new ImageView(this);
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.test);
Drawable d = new CropDrawable(b, 150, 100, 180, 130);
iv.setImageDrawable(d);
setContentView(iv);