java类android.graphics.ColorMatrixColorFilter的实例源码

CoverFlowLayoutManger.java 文件源码 项目:RecyclerCoverFlow 阅读 43 收藏 0 点赞 0 评论 0
/**
     * 变化Item的灰度值
     * @param child 需要设置灰度值的Item
     * @param frame 位置信息
     */
    private void greyItem(View child, Rect frame) {
        float value = computeGreyScale(frame.left - mOffsetAll);
        ColorMatrix cm = new ColorMatrix(new float[]{
                value, 0, 0, 0, 120*(1-value),
                0, value, 0, 0, 120*(1-value),
                0, 0, value, 0, 120*(1-value),
                0, 0, 0, 1, 250*(1-value),
        });
//            cm.setSaturation(0.9f);

        // Create a paint object with color matrix
        Paint greyPaint = new Paint();
        greyPaint.setColorFilter(new ColorMatrixColorFilter(cm));

        // Create a hardware layer with the grey paint
        child.setLayerType(View.LAYER_TYPE_HARDWARE, greyPaint);
        if (value >= 1) {
            // Remove the hardware layer
            child.setLayerType(View.LAYER_TYPE_NONE, null);
        }

    }
PageWidget.java 文件源码 项目:GitHub 阅读 39 收藏 0 点赞 0 评论 0
public PageWidget(Context context, String bookId,
                  List<BookMixAToc.mixToc.Chapters> chaptersList,
                  OnReadStateChangeListener listener) {
    super(context, bookId, chaptersList, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0};
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouch.y = 0.01f;
}
FriskyImageProperty.java 文件源码 项目:FriskyImage 阅读 41 收藏 0 点赞 0 评论 0
public static  Bitmap FriskyEnhanceImage(Bitmap mBitmap, float contrast, float brightness) {
    ColorMatrix cm = new ColorMatrix(new float[]
            {
                    contrast, 0, 0, 0, brightness,
                    0, contrast, 0, 0, brightness,
                    0, 0, contrast, 0, brightness,
                    0, 0, 0, 1, 0
            });
    Bitmap BrightedImage = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), mBitmap
            .getConfig());
    Canvas canvas = new Canvas(BrightedImage);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
    canvas.drawBitmap(mBitmap, 0, 0, paint);
    return BrightedImage;
}
FriskyImageProperty.java 文件源码 项目:FriskyImage 阅读 40 收藏 0 点赞 0 评论 0
public static Bitmap FriskyContrast(Bitmap bitmap,int Value)
{
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.set(new float[] {
            Value, 0, 0, 0, 1,
            0, Value, 0, 0, 1,
            0, 0, Value, 0, 1,
            0, 0, 0, Value, 0   });

    Bitmap BrightedImage = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap
            .getConfig());
    Canvas canvas = new Canvas(BrightedImage);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return BrightedImage;

}
FriskyImageProperty.java 文件源码 项目:FriskyImage 阅读 38 收藏 0 点赞 0 评论 0
public static   Bitmap FriskyBright(Bitmap mBitmap,int fb) {
    ColorMatrix colorMatrix = new ColorMatrix();
     colorMatrix.set(new float[] {
            1, 0, 0, 0, fb,
            0, 1, 0, 0, fb,
            0, 0, 1, 0, fb,
            0, 0, 0, 1, 0   });

    Bitmap BrightedImage = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), mBitmap
            .getConfig());
    Canvas canvas = new Canvas(BrightedImage);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    canvas.drawBitmap(mBitmap, 0, 0, paint);
    return BrightedImage;

}
DragView.java 文件源码 项目:LaunchEnr 阅读 38 收藏 0 点赞 0 评论 0
private void animateFilterTo(float[] targetFilter) {
    float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter;
    mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length);

    if (mFilterAnimator != null) {
        mFilterAnimator.cancel();
    }
    mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter),
            oldFilter, targetFilter);
    mFilterAnimator.setDuration(COLOR_CHANGE_DURATION);
    mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
            invalidate();
        }
    });
    mFilterAnimator.start();
}
SimulationPageAnim.java 文件源码 项目:FriendBook 阅读 47 收藏 0 点赞 0 评论 0
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = { 1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0,1, 0, 0,
            0, 0, 0, 1, 0 };
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
}
ChooserItemViewHolder.java 文件源码 项目:Bridge 阅读 33 收藏 0 点赞 0 评论 0
private void checkSelected() {
    boolean selected = BridgeSettings.isActivityForward(getData().activityInfo.name);
    itemView.setSelected(selected);

    if (!selected) {
        if (filter.get() == null) {
            ColorMatrix cm = new ColorMatrix();
            cm.setSaturation(0);
            ColorMatrixColorFilter grayColorFilter = new ColorMatrixColorFilter(cm);
            filter = new WeakReference<>(grayColorFilter);
        }

        icon.setColorFilter(filter.get());
    } else {
        icon.setColorFilter(null);
    }
}
HighlightingImageView.java 文件源码 项目:Quran 阅读 52 收藏 0 点赞 0 评论 0
public void adjustNightMode() {
  if (isNightMode && !isColorFilterOn) {
    float[] matrix = {
        -1, 0, 0, 0, nightModeTextBrightness,
        0, -1, 0, 0, nightModeTextBrightness,
        0, 0, -1, 0, nightModeTextBrightness,
        0, 0, 0, 1, 0
    };
    setColorFilter(new ColorMatrixColorFilter(matrix));
    isColorFilterOn = true;
  } else if (!isNightMode) {
    clearColorFilter();
    isColorFilterOn = false;
  }

  invalidate();
}
CollectionAdapter.java 文件源码 项目:garras 阅读 37 收藏 0 点赞 0 评论 0
private void startSaturationAnimation(Context context, final AppCompatImageView target) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        target.setHasTransientState(true);
        final AnimUtils.ObservableColorMatrix matrix = new AnimUtils.ObservableColorMatrix();
        final ObjectAnimator saturation = ObjectAnimator.ofFloat(
                matrix, AnimUtils.ObservableColorMatrix.SATURATION, 0f, 1f);
        saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                target.setColorFilter(new ColorMatrixColorFilter(matrix));
            }
        });
        saturation.setDuration(2000);
        saturation.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(context));
        saturation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                target.clearColorFilter();
                target.setHasTransientState(false);
            }
        });
        saturation.start();
    }
}
PhotoAdapter.java 文件源码 项目:garras 阅读 55 收藏 0 点赞 0 评论 0
private void startSaturationAnimation(Context context, final AppCompatImageView target) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        target.setHasTransientState(true);
        final AnimUtils.ObservableColorMatrix matrix = new AnimUtils.ObservableColorMatrix();
        final ObjectAnimator saturation = ObjectAnimator.ofFloat(
                matrix, AnimUtils.ObservableColorMatrix.SATURATION, 0f, 1f);
        saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                target.setColorFilter(new ColorMatrixColorFilter(matrix));
            }
        });
        saturation.setDuration(2000);
        saturation.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(context));
        saturation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                target.clearColorFilter();
                target.setHasTransientState(false);
            }
        });
        saturation.start();
    }
}
ImageUtils.java 文件源码 项目:BBSSDK-for-Android 阅读 44 收藏 0 点赞 0 评论 0
/**
 * 转为灰度图片
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return 灰度图
 */
public static Bitmap toGray(final Bitmap src, final boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    Bitmap ret = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    Canvas canvas = new Canvas(ret);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixColorFilter);
    canvas.drawBitmap(src, 0, 0, paint);
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 46 收藏 0 点赞 0 评论 0
/**
 * 饱和度处理
 *
 * @param bitmap          原图
 * @param saturationValue 新的饱和度值
 * @return 改变了饱和度值之后的图片
 */
public static Bitmap saturation(Bitmap bitmap, int saturationValue) {
    // 计算出符合要求的饱和度值
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 创建一个颜色矩阵
    ColorMatrix saturationColorMatrix = new ColorMatrix();
    // 设置饱和度值
    saturationColorMatrix.setSaturation(newSaturationValue);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturationColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 49 收藏 0 点赞 0 评论 0
/**
 * 亮度处理
 *
 * @param bitmap   原图
 * @param lumValue 新的亮度值
 * @return 改变了亮度值之后的图片
 */
public static Bitmap lum(Bitmap bitmap, int lumValue) {
    // 计算出符合要求的亮度值
    float newlumValue = lumValue * 1.0F / 127;
    // 创建一个颜色矩阵
    ColorMatrix lumColorMatrix = new ColorMatrix();
    // 设置亮度值
    lumColorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(lumColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 41 收藏 0 点赞 0 评论 0
/**
 * 色相处理
 *
 * @param bitmap   原图
 * @param hueValue 新的色相值
 * @return 改变了色相值之后的图片
 */
public static Bitmap hue(Bitmap bitmap, int hueValue) {
    // 计算出符合要求的色相值
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
    // 创建一个颜色矩阵
    ColorMatrix hueColorMatrix = new ColorMatrix();
    // 控制让红色区在色轮上旋转的角度
    hueColorMatrix.setRotate(0, newHueValue);
    // 控制让绿红色区在色轮上旋转的角度
    hueColorMatrix.setRotate(1, newHueValue);
    // 控制让蓝色区在色轮上旋转的角度
    hueColorMatrix.setRotate(2, newHueValue);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(hueColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
SimulationPageAnim.java 文件源码 项目:NovelReader 阅读 49 收藏 0 点赞 0 评论 0
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();

    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = { 1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0,1, 0, 0,
            0, 0, 0, 1, 0 };
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
}
BezelImageView.java 文件源码 项目:odoo-work 阅读 39 收藏 0 点赞 0 评论 0
private void otherInit() {
    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint
            .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}
GrayscaleTransformation.java 文件源码 项目:Glide-transformations 阅读 50 收藏 0 点赞 0 评论 0
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(width, height, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, config);
  }

  Canvas canvas = new Canvas(bitmap);
  ColorMatrix saturation = new ColorMatrix();
  saturation.setSaturation(0f);
  Paint paint = new Paint();
  paint.setColorFilter(new ColorMatrixColorFilter(saturation));
  canvas.drawBitmap(source, 0, 0, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
ImageUtils.java 文件源码 项目:LJFramework 阅读 41 收藏 0 点赞 0 评论 0
/**
 * 转为灰度图片
 *
 * @param src 源图片
 * @param recycle 是否回收
 * @return 灰度图
 */
public static Bitmap toGray(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    Bitmap grayBitmap = Bitmap.createBitmap(src.getWidth(), src
            .getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(grayBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixColorFilter);
    canvas.drawBitmap(src, 0, 0, paint);
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return grayBitmap;
}
FoldingLayoutActivity.java 文件源码 项目:buildAPKsSamples 阅读 31 收藏 0 点赞 0 评论 0
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fold);

    mImageView = (ImageView)findViewById(R.id.image_view);
    mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING,
            ANTIALIAS_PADDING);
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.image));

    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);

    mAnchorSeekBar = (SeekBar)findViewById(R.id.anchor_seek_bar);
    mFoldLayout = (FoldingLayout)findViewById(R.id.fold_view);
    mFoldLayout.setBackgroundColor(Color.BLACK);
    mFoldLayout.setFoldListener(mOnFoldListener);

    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();

    mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);

    mScrollGestureDetector = new GestureDetector(this, new ScrollGestureDetector());
    mItemSelectedListener = new ItemSelectedListener();

    mDefaultPaint = new Paint();
    mSepiaPaint = new Paint();

    ColorMatrix m1 = new ColorMatrix();
    ColorMatrix m2 = new ColorMatrix();
    m1.setSaturation(0);
    m2.setScale(1f, .95f, .82f, 1.0f);
    m1.setConcat(m2, m1);
    mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
}
ContrastView.java 文件源码 项目:EditPhoto 阅读 51 收藏 0 点赞 0 评论 0
private void initView() {
        subject = PublishSubject.create();
        subject.debounce(0, TimeUnit.MILLISECONDS)
//                .filter(new Predicate<Float>() {
//                    @Override
//                    public boolean test(Float contrast) throws Exception {
//                        return true;
//                    }
//                })
                .distinctUntilChanged()
                .switchMap(new Function<Float, ObservableSource<ColorMatrixColorFilter>>() {
                    @Override
                    public ObservableSource<ColorMatrixColorFilter> apply(Float value) throws Exception {
                        return postContrast(value);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ColorMatrixColorFilter>() {
                    @Override
                    public void accept(ColorMatrixColorFilter colorMatrixColorFilter) throws Exception {
                        setColorFilter(colorMatrixColorFilter);
                    }
                });
    }
Utils.java 文件源码 项目:EditPhoto 阅读 39 收藏 0 点赞 0 评论 0
static Bitmap contrastBitmap(Bitmap bitmap, float contrast) {
    float[] colorTransform = new float[]{
            contrast, 0, 0, 0, 0,
            0, contrast, 0, 0, 0,
            0, 0, contrast, 0, 0,
            0, 0, 0, 1, 0};

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0f);
    colorMatrix.set(colorTransform);

    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    Paint paint = new Paint();
    paint.setColorFilter(colorFilter);

    Bitmap resultBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, paint);

    return resultBitmap;
}
SaturationView.java 文件源码 项目:EditPhoto 阅读 33 收藏 0 点赞 0 评论 0
private void initView() {
        subject = PublishSubject.create();
        subject.debounce(0, TimeUnit.MILLISECONDS)
//                .filter(new Predicate<Float>() {
//                    @Override
//                    public boolean test(Float brightness) throws Exception {
//                        return true;
//                    }
//                })
                .distinctUntilChanged()
                .switchMap(new Function<Float, ObservableSource<ColorMatrixColorFilter>>() {
                    @Override
                    public ObservableSource<ColorMatrixColorFilter> apply(Float value) throws Exception {
                        return postBrightness(value);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ColorMatrixColorFilter>() {
                    @Override
                    public void accept(ColorMatrixColorFilter colorMatrixColorFilter) throws Exception {
                        setColorFilter(colorMatrixColorFilter);
                    }
                });
    }
Utils.java 文件源码 项目:EditPhoto 阅读 39 收藏 0 点赞 0 评论 0
public static Bitmap brightBitmap(Bitmap bitmap, int brightness) {
    float[] colorTransform = {
            1, 0, 0, 0, brightness,
            0, 1, 0, 0, brightness,
            0, 0, 1, 0, brightness,
            0, 0, 0, 1, 0};

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0f);
    colorMatrix.set(colorTransform);

    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    Paint paint = new Paint();
    paint.setColorFilter(colorFilter);


    Bitmap resultBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, paint);

    return resultBitmap;
}
Utils.java 文件源码 项目:EditPhoto 阅读 38 收藏 0 点赞 0 评论 0
public static Bitmap contrastBitmap(Bitmap bitmap, int contrast) {
    float[] colorTransform = {
            contrast, 0, 0, 0, 1,
            0, contrast, 0, 0, 1,
            0, 0, contrast, 0, 1,
            0, 0, 0, 1, 0};

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0f);
    colorMatrix.set(colorTransform);

    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    Paint paint = new Paint();
    paint.setColorFilter(colorFilter);


    Bitmap resultBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, paint);

    return resultBitmap;
}
BrightnessView.java 文件源码 项目:EditPhoto 阅读 37 收藏 0 点赞 0 评论 0
private void initView() {
        subject = PublishSubject.create();
        subject.debounce(0, TimeUnit.MILLISECONDS)
//                .filter(new Predicate<Float>() {
//                    @Override
//                    public boolean test(Float brightness) throws Exception {
//                        return true;
//                    }
//                })
                .distinctUntilChanged()
                .switchMap(new Function<Float, ObservableSource<ColorMatrixColorFilter>>() {
                    @Override
                    public ObservableSource<ColorMatrixColorFilter> apply(Float value) throws Exception {
                        return postBrightness(value);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ColorMatrixColorFilter>() {
                    @Override
                    public void accept(ColorMatrixColorFilter colorMatrixColorFilter) throws Exception {
                        setColorFilter(colorMatrixColorFilter);
                    }
                });
    }
Utils.java 文件源码 项目:EditPhoto 阅读 45 收藏 0 点赞 0 评论 0
static Bitmap brightBitmap(Bitmap bitmap, float brightness) {
    float[] colorTransform = {
            1, 0, 0, 0, brightness,
            0, 1, 0, 0, brightness,
            0, 0, 1, 0, brightness,
            0, 0, 0, 1, 0};

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0f);
    colorMatrix.set(colorTransform);

    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    Paint paint = new Paint();
    paint.setColorFilter(colorFilter);


    Bitmap resultBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, paint);

    return resultBitmap;
}
PageWidget.java 文件源码 项目:TextReader 阅读 41 收藏 0 点赞 0 评论 0
public PageWidget(Context context, String bookId,
                  List<BookMixAToc.mixToc.Chapters> chaptersList,
                  OnReadStateChangeListener listener) {
    super(context, bookId, chaptersList, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0};
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouch.y = 0.01f;
}
PageWidget.java 文件源码 项目:BookReader-master 阅读 45 收藏 0 点赞 0 评论 0
public PageWidget(Context context, String bookId,
                  List<BookMixAToc.mixToc.Chapters> chaptersList,
                  OnReadStateChangeListener listener) {
    super(context, bookId, chaptersList, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0};
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouch.y = 0.01f;
}
IosButton.java 文件源码 项目:HumanBody 阅读 33 收藏 0 点赞 0 评论 0
/**
 * 传入改变亮度前的bitmap,返回改变亮度后的bitmap
 * @author leibing
 * @createTime 2016/12/30
 * @lastModify 2016/12/30
 * @param srcBitmap
 * @return
 */
   @SuppressWarnings("deprecation")
public Drawable changeBrightnessBitmap(Bitmap srcBitmap){  
        Bitmap bmp = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(),    
               Config.ARGB_8888);    
       int brightness = 60 - 127;    
       ColorMatrix cMatrix = new ColorMatrix();
    // 改变亮度
       cMatrix.set(new float[] { 1, 0, 0, 0, brightness, 0, 1,    
               0, 0, brightness,
               0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });    
       Paint paint = new Paint();    
       paint.setColorFilter(new ColorMatrixColorFilter(cMatrix));    
       Canvas canvas = new Canvas(bmp);    
       // 在Canvas上绘制一个Bitmap  
       canvas.drawBitmap(srcBitmap, 0, 0, paint);    
      return new BitmapDrawable(bmp);  
   }


问题


面经


文章

微信
公众号

扫码关注公众号