android BitmapDrawable的使用

来源:互联网 发布:中国动员能力知乎 编辑:程序博客网 时间:2024/05/19 00:09
  1.         //功能:显示缩略图,大小为40*40

  2.         //通过openRawResource获取一个inputStream对象  
  3.         InputStream inputStream = getResources().openRawResource(R.drawable.test);  
  4.         //通过一个InputStream创建一个BitmapDrawable对象  
  5.         BitmapDrawable drawable = new BitmapDrawable(inputStream);  
  6.         //通过BitmapDrawable对象获得Bitmap对象  
  7.         Bitmap bitmap = drawable.getBitmap();  
  8.         //利用Bitmap对象创建缩略图  
  9.         bitmap = ThumbnailUtils.extractThumbnail(bitmap, 4040);  
  10.         //imageView 显示缩略图的ImageView  
  11.         imageView.setImageBitmap(bitmap);





  1.  //功能:image2从image1中截取120*120大小后显示,截取起始坐标为(x,y)

  2. BitmapDrawable bitmapDrawable = (BitmapDrawable) image1.getDrawable();
  3. //获取第一个图片显示框中的位图
  4. Bitmapbitmap = bitmapDrawable.getBitmap();
  5. //显示图片的指定区域
  6. image2.setImageBitmap(Bitmap.createBitmap(bitmap, x, y, 120, 120));
  7. image2.setAlpha(alpha);