BitmapDrawable

public class

BitmapDrawable                                          Added in API level 1

extends  Drawable
java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.graphics.drawable.BitmapDrawable
droid.graphics.drawable.BitmapDrawable




<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_launcher"
    android:alpha="20"
    android:antialias="true"
    android:autoMirrored="true"
    android:dither="true"
    android:filter="true"
    android:gravity="center"
    android:mipMap="true"
    android:tileMode="repeat"
    android:tileModeX="repeat"
    android:tileModeY="mirror" 
    >

</bitmap>



       BitmapDrawable bitmapDrawable  =new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
	bitmapDrawable.setAlpha(200);
	bitmapDrawable.setAntiAlias(true);
	bitmapDrawable.setDither(true);
	bitmapDrawable.setMipMap(true);
	bitmapDrawable.setTileModeXY(TileMode.REPEAT, TileMode.MIRROR);
	image.setBackground(bitmapDrawable);


Xml里的alpha 属性设置好像没用,不过可以用代码设置。

android 在 API level 17 加入了 mipmap 技术,对 bitmap 图片的渲染支持 mipmap 技术,

来提高渲染的速度和质量。mipmap 是一种很早就有的技术了,翻译过来就是纹理映射技术

android 中的 mipmap 技术主要为了应对图片大小缩放的处理,在android 中我们提供一个

 bitmap 图片,由于应用的需要(比如缩放动画),可能对这个 bitmap 进行各种比例的缩小,

为了提高缩小的速度和图片的质量,android 通过 mipmap 技术提前对按缩小层级生成图片预

先存储在内存中,这样就提高了图片渲染的速度和质量。

api 中通过 Bitmap 的 public final void setHasMipMap (boolean hasMipMap) 方法可以让

系统渲染器尝试开启 Bitmap 的 mipmap 技术。但是这个方法只能建议系统开启这个功能,

至于是否正真开启,还是由系统决定。

res 目录下面 mipmap 和 drawable 的区别也就是上面这个设置是否开启的区别。

mipmap 目录下的图片默认 setHasMipMap 为 true,drawable 默认 setHasMipMap 为 false。










setXXX



比较好玩的是
public void setColorFilter(ColorFilter cf)

怎么用可以到这里看


getXXX










































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值