如何截取图像的一部分

public class ATActivity extends Activity {
 /** Called when the activity is first created. */
 ImageView iv; android

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  iv = (ImageView) findViewById(R.id.iv);
  Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bottle_day_bg);
1.使用Bitmap的静态方法 ide

  // Bitmap smallBitmap = Bitmap.createBitmap(bitmap, 20, 20, 100, 100);
  // iv.setImageBitmap(smallBitmap); spa

2.使用图像剪切资源
  ClipDrawable cl = (ClipDrawable) iv.getDrawable();
  // 从图像左侧截取图像的30%
  cl.setLevel(3000); code

 }
} xml

图像剪切资源对应的xml ip

 

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipOrientation="horizontal"
    android:drawable="@drawable/bottle_day_bg"
    android:gravity="left" > utf-8

</clip> 资源

相关文章
相关标签/搜索