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


Java ColorMatrix.setSaturation方法代码示例

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


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

示例1: setGreyscale

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
 * 设置View的灰度
 */
public static void setGreyscale(View v, boolean greyscale) {
    if (greyscale) {
        // Create a paint object with 0 saturation (black and white)
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        Paint greyscalePaint = new Paint();
        greyscalePaint.setColorFilter(new ColorMatrixColorFilter(cm));
        // Create a hardware layer with the greyscale paint
        v.setLayerType(LAYER_TYPE_HARDWARE, greyscalePaint);
    } else {
        // Remove the hardware layer
        v.setLayerType(LAYER_TYPE_NONE, null);
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:ResUtil.java

示例2: brightBitmap

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

示例3: 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

示例4: transform

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
@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);
}
 
开发者ID:open-android,项目名称:Glide-transformations,代码行数:24,代码来源:GrayscaleTransformation.java

示例5: brightBitmap

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

示例6: onCreate

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
@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));
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:38,代码来源:FoldingLayoutActivity.java

示例7: toGrayscale

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
 * 图片去色,返回灰度图片
 * 
 * @param bmpOriginal
 *            传入的图片
 * @return 去色后的图片
 */
public static Bitmap toGrayscale(Bitmap bmpOriginal) {
	int width, height;
	height = bmpOriginal.getHeight();
	width = bmpOriginal.getWidth();
	Bitmap bmpGrayscale = Bitmap.createBitmap(width, height,
			Bitmap.Config.RGB_565);
	Canvas c = new Canvas(bmpGrayscale);
	Paint paint = new Paint();
	ColorMatrix cm = new ColorMatrix();
	cm.setSaturation(0);
	ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
	paint.setColorFilter(f);
	c.drawBitmap(bmpOriginal, 0, 0, paint);
	return bmpGrayscale;
}
 
开发者ID:entboost,项目名称:EntboostIM,代码行数:23,代码来源:AbBitmapUtils.java

示例8: transform

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
    int width = toTransform.getWidth();
    int height = toTransform.getHeight();

    Bitmap.Config config = toTransform.getConfig() != null
            ? toTransform.getConfig()
            : Bitmap.Config.ARGB_8888;

    Bitmap bitmap = pool.get(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(toTransform, 0, 0, paint);

    return bitmap;
}
 
开发者ID:esafirm,项目名称:android-image-picker,代码行数:21,代码来源:GrayscaleTransformation.java

示例9: setImageGrayscale

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
 * You can set the image to b/w with this method. Works fine with the
 * opacity.
 * 
 * @param greyscale
 *            true if the grayscale should be activated.
 * @since 1.2.0
 */
public void setImageGrayscale(boolean greyscale) {
	this.greyscale = greyscale;
	if (greyscale) {
		ColorMatrix matrix = new ColorMatrix();
		matrix.setSaturation(0);
		imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
	} else {
		imageView.setColorFilter(null);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:SquareProgressBar.java

示例10: toGray

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

示例11: convertBitmapForColorMode

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
private Bitmap convertBitmapForColorMode(Bitmap original, int colorMode) {
    if (colorMode != 1) {
        return original;
    }
    Bitmap grayscale = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Config.ARGB_8888);
    Canvas c = new Canvas(grayscale);
    Paint p = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0.0f);
    p.setColorFilter(new ColorMatrixColorFilter(cm));
    c.drawBitmap(original, 0.0f, 0.0f, p);
    c.setBitmap(null);
    return grayscale;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:PrintHelperKitkat.java

示例12: desaturateText

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
private void desaturateText(Bitmap current, TextView view) {
    Bitmap overlay = Bitmap.createBitmap(view.getWidth(),
            view.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas part = new Canvas(overlay);
    Paint desat = new Paint();
    ColorMatrix desatMatrix = new ColorMatrix();
    desatMatrix.setSaturation(0.0f);
    desat.setColorFilter(new ColorMatrixColorFilter(desatMatrix));
    part.drawBitmap(current, -view.getLeft(), -view.getTop(), desat);
    view.getPaint().setShader(new BitmapShader(overlay, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
}
 
开发者ID:StylingAndroid,项目名称:PresenterLite,代码行数:13,代码来源:GraphicalLayout.java

示例13: setSaturation

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
public void setSaturation(float sat) {
    saturation = sat;
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(sat);
    ColorFilter filter = new ColorMatrixColorFilter(cm);
    getDrawable().setColorFilter(filter);
}
 
开发者ID:StylingAndroid,项目名称:PresenterLite,代码行数:8,代码来源:FilteredImageView.java

示例14: init

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
private void init() {
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mPaint = new Paint();
//        ColorFilter filter = new PorterDuffColorFilter(SettingsManager.get().getState().isDarkTheme() ?
//                // material design: disabled text color is white with 50% opacity
//                ColorUtils.setAlphaComponent(Color.WHITE, 128) :
//                // material design: disabled text color is black with 38% opacity
//                ColorUtils.setAlphaComponent(Color.BLACK, 97), PorterDuff.Mode.SRC_ATOP);
//        ColorFilter filter = new PorterDuffColorFilter(SettingsManager.get().getState().isDarkTheme() ? Color.GRAY : Color.LTGRAY, PorterDuff.Mode.SRC_ATOP);
        ColorFilter filter = new PorterDuffColorFilter(SettingsManager.get().getState().isDarkTheme() ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        mPaint.setColorFilter(filter);
        mPaint.setAlpha(SettingsManager.get().getState().isDarkTheme() ? 128 : 97);
//        mPaint.setColorFilter(new ColorMatrixColorFilter(cm));
    }
 
开发者ID:MFlisar,项目名称:RecyclerViewPreferences,代码行数:16,代码来源:SettingsRootView.java

示例15: AppAdapter

import android.graphics.ColorMatrix; //导入方法依赖的package包/类
public AppAdapter(Activity activity, RecyclerView recyclerView) {
    super(activity, recyclerView);
    mResources = activity.getResources();
    mMatrix = new ColorMatrix();
    mMatrix.setSaturation(0); // 参数大于1将增加饱和度,0~1之间会减少饱和度。0值将产生一幅灰度图像。
    mColorFilterGrey = new ColorMatrixColorFilter(mMatrix);
    mMatrix.setSaturation(1); // 参数大于1将增加饱和度,0~1之间会减少饱和度。0值将产生一幅灰度图像。
    mColorFilterNormal = new ColorMatrixColorFilter(mMatrix);
    mMatrix.setSaturation(0.2f); // 参数大于1将增加饱和度,0~1之间会减少饱和度。0值将产生一幅灰度图像。
    mColorFilter50 = new ColorMatrixColorFilter(mMatrix);
}
 
开发者ID:XYScience,项目名称:StopApp,代码行数:12,代码来源:AppAdapter.java


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