当前位置: 首页>>代码示例>>Java>>正文


Java ColorMatrix类代码示例

本文整理汇总了Java中android.graphics.ColorMatrix的典型用法代码示例。如果您正苦于以下问题:Java ColorMatrix类的具体用法?Java ColorMatrix怎么用?Java ColorMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ColorMatrix类属于android.graphics包,在下文中一共展示了ColorMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: greyItem

import android.graphics.ColorMatrix; //导入依赖的package包/类
/**
     * 变化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);
        }

    }
 
开发者ID:ChenLittlePing,项目名称:RecyclerCoverFlow,代码行数:28,代码来源:CoverFlowLayoutManger.java

示例2: rotateColor

import android.graphics.ColorMatrix; //导入依赖的package包/类
private int rotateColor(int color, float rad) {
    float deg = rad * 180 / 3.1415927f;
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    ColorMatrix cm = new ColorMatrix();
    ColorMatrix tmp = new ColorMatrix();

    cm.setRGB2YUV();
    tmp.setRotate(0, deg);
    cm.postConcat(tmp);
    tmp.setYUV2RGB();
    cm.postConcat(tmp);

    final float[] a = cm.getArray();

    int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b);
    int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b);
    int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b);

    return Color.argb(Color.alpha(color), pinToByte(ir),
            pinToByte(ig), pinToByte(ib));
}
 
开发者ID:Edward-Yung,项目名称:Mu-Retargeter-1.0,代码行数:25,代码来源:ColorPickerDialog.java

示例3: PageWidget

import android.graphics.ColorMatrix; //导入依赖的package包/类
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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:PageWidget.java

示例4: updateYUVfromRGB

import android.graphics.ColorMatrix; //导入依赖的package包/类
/**
 * Keep all colorspace representations in sync.
 */
private void updateYUVfromRGB() {
	float r = mRGB[0] / 255.0f;
	float g = mRGB[1] / 255.0f;
	float b = mRGB[2] / 255.0f;

	ColorMatrix cm = new ColorMatrix();
	cm.setRGB2YUV();
	final float[] a = cm.getArray();

	mYUV[0] = a[0] * r + a[1] * g + a[2] * b;
	mYUV[0] = pinToUnit(mYUV[0]);
	mYUV[1] = a[5] * r + a[6] * g + a[7] * b;
	mYUV[1] = pin(mYUV[1], -.5f, .5f);
	mYUV[2] = a[10] * r + a[11] * g + a[12] * b;
	mYUV[2] = pin(mYUV[2], -.5f, .5f);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:UberColorPickerDialog.java

示例5: FriskyEnhanceImage

import android.graphics.ColorMatrix; //导入依赖的package包/类
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;
}
 
开发者ID:Dwijraj,项目名称:FriskyImage,代码行数:17,代码来源:FriskyImageProperty.java

示例6: FriskyContrast

import android.graphics.ColorMatrix; //导入依赖的package包/类
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;

}
 
开发者ID:Dwijraj,项目名称:FriskyImage,代码行数:19,代码来源:FriskyImageProperty.java

示例7: FriskyBright

import android.graphics.ColorMatrix; //导入依赖的package包/类
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;

}
 
开发者ID:Dwijraj,项目名称:FriskyImage,代码行数:18,代码来源:FriskyImageProperty.java

示例8: animateFilterTo

import android.graphics.ColorMatrix; //导入依赖的package包/类
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();
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:21,代码来源:DragView.java

示例9: SimulationPageAnim

import android.graphics.ColorMatrix; //导入依赖的package包/类
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;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:23,代码来源:SimulationPageAnim.java

示例10: checkSelected

import android.graphics.ColorMatrix; //导入依赖的package包/类
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);
    }
}
 
开发者ID:RikkaW,项目名称:Bridge,代码行数:18,代码来源:ChooserItemViewHolder.java

示例11: toGray

import android.graphics.ColorMatrix; //导入依赖的package包/类
/**
 * 转为灰度图片
 *
 * @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;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:25,代码来源:ImageUtils.java

示例12: saturation

import android.graphics.ColorMatrix; //导入依赖的package包/类
/**
 * 饱和度处理
 *
 * @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;
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:26,代码来源:XBitmapUtils.java

示例13: lum

import android.graphics.ColorMatrix; //导入依赖的package包/类
/**
 * 亮度处理
 *
 * @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;
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:26,代码来源:XBitmapUtils.java

示例14: hue

import android.graphics.ColorMatrix; //导入依赖的package包/类
/**
 * 色相处理
 *
 * @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;
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:30,代码来源:XBitmapUtils.java

示例15: SimulationPageAnim

import android.graphics.ColorMatrix; //导入依赖的package包/类
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;
}
 
开发者ID:newbiechen1024,项目名称:NovelReader,代码行数:24,代码来源:SimulationPageAnim.java


注:本文中的android.graphics.ColorMatrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。