Android Drawable Resources系列1:Bitmap(dither图像抖动、tileMode平铺模式)

一、Bitmap File:可以使用.png, .jpg, or .gif文件,路径:res/drawable/filename.png (.png, .jpg, or .gif)

一般使用,res/drawable/myimage.png,
<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/myimage" />
或者代码中使用
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.myimage);

二、XML Bitmap:在res目录下创建xml文件:res/drawable/filename.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@[package:]drawable/drawable_resource"
    android:antialias=["true" | "false"]
    android:dither=["true" | "false"]
    android:filter=["true" | "false"]
    android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
                      "fill_vertical" | "center_horizontal" | "fill_horizontal" |
                      "center" | "fill" | "clip_vertical" | "clip_horizontal"]
    android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />

参数名作用备注
antialias
设置是否使用抗锯齿功能。
 
dither
设定是否使用图像抖动处理,会使绘制出来的图片颜色更加平滑和饱满,图像更加清晰。
 
filter启用或禁用位图过滤,过滤时会使图像收缩或拉伸显示更加平滑。 
gravity设置位置。 
tileMode定义平铺模式:
disabled:不使用平铺。
clamp:复制边缘色彩。
repeat:重复图片显示。
mirror:镜像显示。
 

三、代码方式:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);  
BitmapDrawable bd = new BitmapDrawable(bitmap);  
bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );  
bd.setDither(true);  
view.setBackgroundDrawable(bd);  

示例disabled:


示例clamp:


示例repeat:


示例mirror:




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值