本文整理汇总了Java中android.graphics.ColorMatrix.setScale方法的典型用法代码示例。如果您正苦于以下问题:Java ColorMatrix.setScale方法的具体用法?Java ColorMatrix.setScale怎么用?Java ColorMatrix.setScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.ColorMatrix
的用法示例。
在下文中一共展示了ColorMatrix.setScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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));
}
示例3: handleImageEffect
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
public static Bitmap handleImageEffect(Bitmap bm, float lum) {
Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
ColorMatrix lumMatrix = new ColorMatrix();
lumMatrix.setScale(lum, lum, lum, 1);
ColorMatrix imageMatrix = new ColorMatrix();
imageMatrix.postConcat(lumMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
canvas.drawBitmap(bm, 0, 0, paint);
return bmp;
}
示例4: setBackground
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
public static void setBackground(View v, Bitmap bm) {
if (bm == null) {
v.setBackgroundResource(0);
return;
}
int vwidth = v.getWidth()/4;
int vheight = v.getHeight()/4;
int bwidth = bm.getWidth();
int bheight = bm.getHeight();
float scalex = (float) vwidth / bwidth;
float scaley = (float) vheight / bheight;
float scale = Math.max(scalex, scaley) * 1.3f;
Bitmap.Config config = Bitmap.Config.ARGB_8888;
Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
Canvas c = new Canvas(bg);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
ColorMatrix greymatrix = new ColorMatrix();
greymatrix.setSaturation(0);
ColorMatrix darkmatrix = new ColorMatrix();
darkmatrix.setScale(1f, 1f, 1f, .1f);
greymatrix.postConcat(darkmatrix);
ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
paint.setColorFilter(filter);
Matrix matrix = new Matrix();
matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
matrix.postRotate(10);
matrix.postScale(scale, scale);
matrix.postTranslate(vwidth/2, vheight/2); // Move bitmap center to view center
c.drawBitmap(bm, matrix, paint);
v.setBackgroundDrawable(new BitmapDrawable(bg));
}
示例5: 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(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
// 将原图使用给定的画笔画到画布上
canvas.drawBitmap(bitmap, 0, 0, paint);
return newBitmap;
}
示例6: 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;
}
示例7: handleImageEffect
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
* 调整照片的色调,饱和度,亮度
* MID_VALUE = 177; // 进度条的中间值
* @param bm 原图
* @param hue 色调 = (进度条进度 - MID_VALUE) * 1.0F / MIN_VALUE * 180
* @param saturation 饱和度 = 进度条进度 * 1.0F / MIN_VALUE;
* @param lum 亮度 = 进度条进度 * 1.0F / MIN_VALUE;
* @return 调整后的图片
*/
public static Bitmap handleImageEffect(Bitmap bm, int hue, int saturation, int lum) {
Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
ColorMatrix hueMatrix = new ColorMatrix();
hueMatrix.setRotate(0,hue);
hueMatrix.setRotate(1,hue);
hueMatrix.setRotate(2, hue);
ColorMatrix saturationMatrix = new ColorMatrix();
saturationMatrix.setSaturation(saturation);
ColorMatrix lumMatrix = new ColorMatrix();
lumMatrix.setScale(lum,lum,lum,1);
ColorMatrix imageMatrix = new ColorMatrix();
imageMatrix.postConcat(hueMatrix);
imageMatrix.postConcat(saturationMatrix);
imageMatrix.postConcat(lumMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
canvas.drawBitmap(bm,0,0,paint);
return bitmap;
}
示例8: lumAndHueAndSaturation
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
* 亮度、色相、饱和度处理
*
* @param bitmap 原图
* @param lumValue 亮度值
* @param hueValue 色相值
* @param saturationValue 饱和度值
* @return 亮度、色相、饱和度处理后的图片
*/
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue,
int hueValue, int saturationValue) {
// 计算出符合要求的饱和度值
float newSaturationValue = saturationValue * 1.0F / 127;
// 计算出符合要求的亮度值
float newlumValue = lumValue * 1.0F / 127;
// 计算出符合要求的色相值
float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
// 创建一个颜色矩阵并设置其饱和度
ColorMatrix colorMatrix = new ColorMatrix();
// 设置饱和度值
colorMatrix.setSaturation(newSaturationValue);
// 设置亮度值
colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
// 控制让红色区在色轮上旋转的角度
colorMatrix.setRotate(0, newHueValue);
// 控制让绿红色区在色轮上旋转的角度
colorMatrix.setRotate(1, newHueValue);
// 控制让蓝色区在色轮上旋转的角度
colorMatrix.setRotate(2, newHueValue);
// 创建一个画笔并设置其颜色过滤器
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
// 创建一个新的图片并创建画布
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
// 将原图使用给定的画笔画到画布上
canvas.drawBitmap(bitmap, 0, 0, paint);
return newBitmap;
}
示例9: handleImageEffect
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
* 颜色效果
*/
public static Bitmap handleImageEffect(Bitmap bm, float hue, float saturation, float lum) {
Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
//色调
ColorMatrix hueMatrix = new ColorMatrix();
hueMatrix.setRotate(0, hue); //Red
hueMatrix.setRotate(1, hue); //Green
hueMatrix.setRotate(2, hue); //Blue
//饱和度
ColorMatrix saturationMatrix = new ColorMatrix();
saturationMatrix.setSaturation(saturation);
//亮度
ColorMatrix lumMatrix = new ColorMatrix();
lumMatrix.setScale(lum, lum, lum, 1);
ColorMatrix imageMatrix = new ColorMatrix();
imageMatrix.postConcat(hueMatrix);
imageMatrix.postConcat(saturationMatrix);
imageMatrix.postConcat(lumMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
canvas.drawBitmap(bm, 0, 0, paint);
return bmp;
}
示例10: lumAndHueAndSaturation
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
* 亮度、色相、饱和度处理
*
* @param bitmap 原图
* @param lumValue 亮度值
* @param hueValue 色相值
* @param saturationValue 饱和度值
* @return 亮度、色相、饱和度处理后的图片
*/
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue,
int hueValue, int saturationValue) {
// 计算出符合要求的饱和度值
float newSaturationValue = saturationValue * 1.0F / 127;
// 计算出符合要求的亮度值
float newlumValue = lumValue * 1.0F / 127;
// 计算出符合要求的色相值
float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
// 创建一个颜色矩阵并设置其饱和度
ColorMatrix colorMatrix = new ColorMatrix();
// 设置饱和度值
colorMatrix.setSaturation(newSaturationValue);
// 设置亮度值
colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
// 控制让红色区在色轮上旋转的角度
colorMatrix.setRotate(0, newHueValue);
// 控制让绿红色区在色轮上旋转的角度
colorMatrix.setRotate(1, newHueValue);
// 控制让蓝色区在色轮上旋转的角度
colorMatrix.setRotate(2, newHueValue);
// 创建一个画笔并设置其颜色过滤器
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
// 创建一个新的图片并创建画布
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
// 将原图使用给定的画笔画到画布上
canvas.drawBitmap(bitmap, 0, 0, paint);
return newBitmap;
}
示例11: lumAndHueAndSaturation
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
* 亮度、色相、饱和度处理
*
* @param bitmap 原图
* @param lumValue 亮度值
* @param hueValue 色相值
* @param saturationValue 饱和度值
* @return 亮度、色相、饱和度处理后的图片
*/
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue, int hueValue, int saturationValue) {
// 计算出符合要求的饱和度值
float newSaturationValue = saturationValue * 1.0F / 127;
// 计算出符合要求的亮度值
float newlumValue = lumValue * 1.0F / 127;
// 计算出符合要求的色相值
float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
// 创建一个颜色矩阵并设置其饱和度
ColorMatrix colorMatrix = new ColorMatrix();
// 设置饱和度值
colorMatrix.setSaturation(newSaturationValue);
// 设置亮度值
colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
// 控制让红色区在色轮上旋转的角度
colorMatrix.setRotate(0, newHueValue);
// 控制让绿红色区在色轮上旋转的角度
colorMatrix.setRotate(1, newHueValue);
// 控制让蓝色区在色轮上旋转的角度
colorMatrix.setRotate(2, newHueValue);
// 创建一个画笔并设置其颜色过滤器
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
// 创建一个新的图片并创建画布
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
// 将原图使用给定的画笔画到画布上
canvas.drawBitmap(bitmap, 0, 0, paint);
return newBitmap;
}
示例12: transform
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
@Override
public Bitmap transform(final Bitmap source) {
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
ColorMatrix grayScaleMatrix = new ColorMatrix();
grayScaleMatrix.setSaturation(0f);
ColorMatrix tintMatrix = new ColorMatrix();
tintMatrix.setScale(Color.red(color) / MAX_LUMINOSITY,
Color.green(color) / MAX_LUMINOSITY,
Color.blue(color) / MAX_LUMINOSITY,
Color.alpha(color) / MAX_LUMINOSITY);
grayScaleMatrix.postConcat(tintMatrix);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(grayScaleMatrix);
Paint paint = new Paint();
paint.setColor(color);
paint.setColorFilter(filter);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, 0, 0, paint);
source.recycle();
return bitmap;
}
示例13: setBrightnessMatrix
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
private static void setBrightnessMatrix(ColorMatrix matrix, int brightness) {
// Brightness: C-new = C-old*(1-amount) + amount
float scale = 1 - brightness / 255.0f;
matrix.setScale(scale, scale, scale, 1);
float[] array = matrix.getArray();
// Add the amount to RGB components of the matrix, as per the above formula.
// Fifth elements in the array correspond to the constant being added to
// red, blue, green, and alpha channel respectively.
array[4] = brightness;
array[9] = brightness;
array[14] = brightness;
}
示例14: handleImageMatrix
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
/**
* 根据具体给定的bitmap,色调 饱和度及亮度生成新的bitmap
*
* @param tone 色调
* @param saturation 饱和度
* @param lum 亮度
* @return new bitmap
*/
public static Bitmap handleImageMatrix(Bitmap bm, float tone, float saturation, float lum) {
Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
// 色调
ColorMatrix toneMatrix = new ColorMatrix();
toneMatrix.setRotate(0, tone);
toneMatrix.setRotate(1, tone);
toneMatrix.setRotate(2, tone);
// 饱和度
ColorMatrix saturationMatrix = new ColorMatrix();
saturationMatrix.setSaturation(saturation);
// 亮度
ColorMatrix lumMatrix = new ColorMatrix();
lumMatrix.setScale(lum, lum, lum, 1);
ColorMatrix imageMatrix = new ColorMatrix();
imageMatrix.postConcat(toneMatrix);
imageMatrix.postConcat(saturationMatrix);
imageMatrix.postConcat(lumMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
canvas.drawBitmap(bm, 0, 0, paint);
return bitmap;
}
示例15: setColorScale
import android.graphics.ColorMatrix; //导入方法依赖的package包/类
public static void setColorScale(int color, ColorMatrix target) {
target.setScale(Color.red(color) / 255f, Color.green(color) / 255f,
Color.blue(color) / 255f, Color.alpha(color) / 255f);
}