切割drawable

public Drawable getWallpaper1(Drawable wallpaperDrawable, int cutHeight){
  final float scale = getResources().getDisplayMetrics().density;
  int temp_height = wallpaperDrawable.getIntrinsicHeight();
  int temp_width = wallpaperDrawable.getIntrinsicWidth();
  float height = Math.max(temp_height, temp_width)/scale;
  float width = Math.min(temp_height, temp_width)/scale;
  Bitmap bitmapWithReflection = Bitmap.createBitmap((int)width, (int)(height-cutHeight), Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmapWithReflection);
  Paint paint = new Paint();
  wallpaperDrawable.setBounds(0, -cutHeight, (int)width, (int)(height-cutHeight));
  wallpaperDrawable.draw(canvas);
  canvas.drawBitmap(bitmapWithReflection, 0, 0, paint);

  return new BitmapDrawable(bitmapWithReflection);
}

posted on 2012-12-14 14:40  crazylost  阅读(185)  评论(0)    收藏  举报