本文整理匯總了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);
}
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}