當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。