Java Code Examples for android.graphics.ColorMatrix#set()

The following examples show how to use android.graphics.ColorMatrix#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SampleWhackyColorFilter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addOverlays() {

    //p.s. there's a ton of examples here
    //http://stackoverflow.com/questions/4354939/understanding-the-use-of-colormatrix-and-colormatrixcolorfilter-to-modify-a-draw
    //http://developer.android.com/reference/android/graphics/ColorMatrix.html

    //this will make things look pinkish
    //this.mMapView.getOverlayManager().getTilesOverlay().setColorFilter(adjustHue(160));

    ColorMatrix cm = new ColorMatrix();
    float brightness =.5f;  // reduce color's by 50%. i.e. just make it darker
    cm.set(new float[] {
            brightness, 0, 0, 0, 0,    //red
            0, brightness, 0, 0, 0,    //green
            0, 0, brightness, 0, 0,    //blue
            0, 0, 0, 1, 0});    //alpha

    this.mMapView.getOverlayManager().getTilesOverlay().setColorFilter(new ColorMatrixColorFilter(cm));

    //pro tip, set the color filter to null to reset to normal viewing
}
 
Example 2
Source File: BitmapManipulator.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
static Bitmap setBitmapBrightness(Bitmap bitmap, float brightness)
{
    if (bitmap == null)
        return null;

    float[] colorTransform = {
            1f, 0, 0, 0, brightness,
            0, 1f, 0, 0, brightness,
            0, 0, 1f, 0, brightness,
            0, 0, 0, 1f, 0};

    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(),
            bitmap.getConfig());
    Canvas canvas = new Canvas(newBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.set(colorTransform);
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    Matrix matrix = new Matrix();
    canvas.drawBitmap(bitmap, matrix, paint);

    return newBitmap;
}
 
Example 3
Source File: SimulationPageAnim.java    From FriendBook with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: PageWidget.java    From fangzhuishushenqi with Apache License 2.0 6 votes vote down vote up
public PageWidget(Context context, String bookId,
                  List<BookToc.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;
}
 
Example 5
Source File: BrokenAnimator.java    From BrokenView with MIT License 6 votes vote down vote up
private void buildPaintShader(){
    if(mConfig.paint == null) {
        onDrawPaint = new Paint();
        BitmapShader shader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Matrix matrix = new Matrix();
        // Refraction effect
        matrix.setTranslate(-offsetX - 10, -offsetY - 7);
        shader.setLocalMatrix(matrix);
        ColorMatrix cMatrix = new ColorMatrix();
        // Increase saturation and brightness
        cMatrix.set(new float[]{
                2.5f, 0, 0, 0, 100,
                0, 2.5f, 0, 0, 100,
                0, 0, 2.5f, 0, 100,
                0, 0, 0, 1, 0});
        onDrawPaint.setColorFilter(new ColorMatrixColorFilter(cMatrix));
        onDrawPaint.setShader(shader);
        onDrawPaint.setStyle(Paint.Style.FILL);
    }
    else
        onDrawPaint = mConfig.paint;
}
 
Example 6
Source File: SimulationPageAnim.java    From NovelReader with MIT License 6 votes vote down vote up
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mXORPath = 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;
}
 
Example 7
Source File: PageWidget.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public PageWidget(Context context) {
	super(context);

	// TODO Auto-generated constructor stub
	mPath0 = new Path();
	mPath1 = new Path();
	createDrawable();

	mPaint = new Paint();
	mPaint.setStyle(Paint.Style.FILL);

	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();
	mScroller = new Scroller(getContext());

	mTouch.x = 0.01f;
	mTouch.y = 0.01f;
}
 
Example 8
Source File: IosButton.java    From HumanBody with Apache License 2.0 6 votes vote down vote up
/**
 * 传入改变亮度前的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);  
   }
 
Example 9
Source File: PageWidget.java    From BookReader with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 10
Source File: pageView.java    From Jreader with GNU General Public License v2.0 6 votes vote down vote up
public pageView(Context context, int width, int height) {
    super(context);
    mPath0 = new Path();
    mPath1 = new Path();
    mScreenWidth = width;
    mScreenHeight = height;

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组  4*5颜色矩阵
    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();
    mScroller = new Scroller(getContext());

    mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouch.y = 0.01f;
}
 
Example 11
Source File: PageWidget.java    From Jreader with GNU General Public License v2.0 6 votes vote down vote up
public PageWidget(Context context, int width, int height) {
    super(context);
    mPath0 = new Path();
    mPath1 = new Path();
    mScreenWidth = width;
    mScreenHeight = height;
    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();
    mScroller = new Scroller(getContext());

    mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouch.y = 0.01f;
}
 
Example 12
Source File: PageView.java    From android-open-source-project-analysis with Apache License 2.0 5 votes vote down vote up
public PageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        initPage();

        mPath0 = new Path();
        mPath1 = new Path();
        mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.FILL);
//        mPaint.setAlpha(150);

        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 };
        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();
        mScroller = new Scroller(getContext(),new LinearInterpolator());

        mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
        mTouch.y = 0.01f;
    }
 
Example 13
Source File: ViewHelper.java    From Utils with Apache License 2.0 5 votes vote down vote up
private static ColorMatrixColorFilter getBrightnessMatrixColorFilter(float brightness) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.set(
            new float[]{
                    1, 0, 0, 0, brightness,
                    0, 1, 0, 0, brightness,
                    0, 0, 1, 0, brightness,
                    0, 0, 0, 1, 0
            });
    return new ColorMatrixColorFilter(matrix);
}
 
Example 14
Source File: PageWidget.java    From coolreader with MIT License 5 votes vote down vote up
public PageWidget(Context context,AttributeSet set) {
	super(context,set);
	Log.d("dot","one attr");
	this.context=context;
	DisplayMetrics dm = new DisplayMetrics();
	((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(dm);
	mWidth = dm.widthPixels;
	mHeight = dm.heightPixels-AppUtil.dip2px(context, 50);
    mDisplayMaxLength = (float) Math.hypot(mWidth, mHeight);
	mPath0 = new Path();
	mPath1 = new Path();
	createDrawable();   
	mshow=true;
	mPaint = new Paint();
	mPaint.setStyle(Paint.Style.FILL);

	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();
	mScroller = new Scroller(getContext());

	mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
	mTouch.y = 0.01f;
}
 
Example 15
Source File: ResultActivity.java    From TextOcrExample with Apache License 2.0 5 votes vote down vote up
/**
 * 改变亮度
 */
public Bitmap changeLight(Bitmap bitmap, int brightness) {
    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(bitmap);
    // 在Canvas上绘制一个已经存在的Bitmap。这样,dstBitmap就和srcBitmap一摸一样了
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return bitmap;
}
 
Example 16
Source File: RFABViewUtil.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static ColorMatrixColorFilter getBrightnessMatrixColorFilter(float brightness) {
    ColorMatrix matrix = new ColorMatrix();
    matrix.set(
            new float[]{
                    1, 0, 0, 0, brightness,
                    0, 1, 0, 0, brightness,
                    0, 0, 1, 0, brightness,
                    0, 0, 0, 1, 0
            });
    return new ColorMatrixColorFilter(matrix);
}
 
Example 17
Source File: BaseTextRenderer.java    From Ansole with GNU General Public License v2.0 4 votes vote down vote up
public BaseTextRenderer(ColorScheme scheme) {
    if (scheme == null) {
        scheme = defaultColorScheme;
    }
    setDefaultColors(scheme);

    mCursorScreenPaint = new Paint();
    mCursorScreenPaint.setColor(scheme.getCursorBackColor());

    // Cursor paint and cursor stroke paint are used to draw a grayscale mask that's converted
    // to an alpha8 texture. Only the red channel's value matters.
    mCursorPaint = new Paint();
    mCursorPaint.setColor(0xff909090); // Opaque lightgray
    mCursorPaint.setAntiAlias(true);

    mCursorStrokePaint = new Paint(mCursorPaint);
    mCursorStrokePaint.setStrokeWidth(0.1f);
    mCursorStrokePaint.setStyle(Paint.Style.STROKE);

    mCopyRedToAlphaPaint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.set(new float[] {
            0, 0, 0, 0, 0,
            0, 0, 0, 0, 0,
            0, 0, 0, 0, 0,
            1, 0, 0, 0, 0 });
    mCopyRedToAlphaPaint.setColorFilter(new ColorMatrixColorFilter(cm));

    mShiftCursor = new Path();
    mShiftCursor.lineTo(0.5f, 0.33f);
    mShiftCursor.lineTo(1.0f, 0.0f);

    mAltCursor = new Path();
    mAltCursor.moveTo(0.0f, 1.0f);
    mAltCursor.lineTo(0.5f, 0.66f);
    mAltCursor.lineTo(1.0f, 1.0f);

    mCtrlCursor = new Path();
    mCtrlCursor.moveTo(0.0f, 0.25f);
    mCtrlCursor.lineTo(1.0f, 0.5f);
    mCtrlCursor.lineTo(0.0f, 0.75f);

    mFnCursor = new Path();
    mFnCursor.moveTo(1.0f, 0.25f);
    mFnCursor.lineTo(0.0f, 0.5f);
    mFnCursor.lineTo(1.0f, 0.75f);

    // For creating the transform when the terminal resizes
    mTempSrc = new RectF();
    mTempSrc.set(0.0f, 0.0f, 1.0f, 1.0f);
    mTempDst = new RectF();
    mScaleMatrix = new Matrix();
}
 
Example 18
Source File: LightningView.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Sets the current rendering color of the WebView instance
 * of the current LightningView. The for modes are normal
 * rendering (0), inverted rendering (1), grayscale rendering (2),
 * and inverted grayscale rendering (3)
 *
 * @param mode the integer mode to set as the rendering mode.
 *             see the numbers in documentation above for the
 *             values this method accepts.
 */
private void setColorMode(int mode) {
    mInvertPage = false;
    switch (mode) {
        case 0:
            mPaint.setColorFilter(null);
            // setSoftwareRendering(); // Some devices get segfaults
            // in the WebView with Hardware Acceleration enabled,
            // the only fix is to disable hardware rendering
            setNormalRendering();
            mInvertPage = false;
            break;
        case 1:
            ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
                sNegativeColorArray);
            mPaint.setColorFilter(filterInvert);
            setHardwareRendering();

            mInvertPage = true;
            break;
        case 2:
            ColorMatrix cm = new ColorMatrix();
            cm.setSaturation(0);
            ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
            mPaint.setColorFilter(filterGray);
            setHardwareRendering();
            break;
        case 3:
            ColorMatrix matrix = new ColorMatrix();
            matrix.set(sNegativeColorArray);
            ColorMatrix matrixGray = new ColorMatrix();
            matrixGray.setSaturation(0);
            ColorMatrix concat = new ColorMatrix();
            concat.setConcat(matrix, matrixGray);
            ColorMatrixColorFilter filterInvertGray = new ColorMatrixColorFilter(concat);
            mPaint.setColorFilter(filterInvertGray);
            setHardwareRendering();

            mInvertPage = true;
            break;

        case 4:
            ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter(
                sIncreaseContrastColorArray);
            mPaint.setColorFilter(IncreaseHighContrast);
            setHardwareRendering();
            break;

    }

}
 
Example 19
Source File: LetvTools.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void changeLight(View imageView, int brightness) {
    ColorMatrix cMatrix = new ColorMatrix();
    cMatrix.set(new float[]{1.0f, 0.0f, 0.0f, 0.0f, (float) brightness, 0.0f, 1.0f, 0.0f, 0.0f, (float) brightness, 0.0f, 0.0f, 1.0f, 0.0f, (float) brightness, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f});
    ((ImageView) imageView).setColorFilter(new ColorMatrixColorFilter(cMatrix));
}
 
Example 20
Source File: LightningView.java    From browser with GNU General Public License v2.0 4 votes vote down vote up
public void setColorMode(int mode) {
	mInvertPage = false;
	switch (mode) {
		case 0:
			mPaint.setColorFilter(null);
			 //setSoftwareRendering(); // Some devices get segfaults
			// in the WebView with Hardware Acceleration enabled,
			// the only fix is to disable hardware rendering
			//setNormalRendering();
			setHardwareRendering();
			mInvertPage = false;
			break;
		case 1:
			ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
					mNegativeColorArray);
			mPaint.setColorFilter(filterInvert);
			setHardwareRendering();

			mInvertPage = true;
			break;
		case 2:
			ColorMatrix cm = new ColorMatrix();
			cm.setSaturation(0);
			ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
			mPaint.setColorFilter(filterGray);
			setHardwareRendering();
			break;
		case 3:
			ColorMatrix matrix = new ColorMatrix();
			matrix.set(mNegativeColorArray);
			ColorMatrix matrixGray = new ColorMatrix();
			matrixGray.setSaturation(0);
			ColorMatrix concat = new ColorMatrix();
			concat.setConcat(matrix, matrixGray);
			ColorMatrixColorFilter filterInvertGray = new ColorMatrixColorFilter(concat);
			mPaint.setColorFilter(filterInvertGray);
			setHardwareRendering();

			mInvertPage = true;
			break;

	}

}