首页 > 技术文章 > Android开发 ImageView开发记录

guanxinjing 2019-09-20 17:52 原文

改变图片的着色

默认是这个方法

/**
     * 为图像设置着色选项. Assumes
     * {@link PorterDuff.Mode#SRC_ATOP} blending mode.
     *
     * @param color Color tint to apply.
     * @attr ref android.R.styleable#ImageView_tint
     */
    @RemotableViewMethod
    public final void setColorFilter(int color) {
        setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }

还可以使用输入交集/并集等等属性的方式改变图片配色

/**
     * Sets a tinting option for the image.
     *
     * @param color Color tint to apply.
     * @param mode How to apply the color.  The standard mode is
     * {@link PorterDuff.Mode#SRC_ATOP}
     *
     * @attr ref android.R.styleable#ImageView_tint
     */
    public final void setColorFilter(int color, PorterDuff.Mode mode) {
        setColorFilter(new PorterDuffColorFilter(color, mode));
    }

android:scaleType

  • CENTER /center   按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示 
  • CENTER_CROP / centerCrop   按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽) 
  • CENTER_INSIDE / centerInside   将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽 
  • FIT_CENTER / fitCenter   把图片按比例扩大/缩小到View的宽度,居中显示 
  • FIT_END / fitEnd   把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置 
  • FIT_START / fitStart  把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置 
  • FIT_XY / fitXY   把图片 不按比例

 

高斯模糊

 https://www.jianshu.com/p/02da487a2f43

 

end

推荐阅读