use of android.graphics.Canvas in project TwinklingRefreshLayout by lcodecorex.
the class CircleImageView method getBitmapFromDrawable.
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
if (!(drawable.getIntrinsicWidth() > 0) || !(drawable.getIntrinsicHeight() > 0)) {
bitmap = Bitmap.createBitmap(DensityUtil.dip2px(getContext(), 40), DensityUtil.dip2px(getContext(), 40), BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
return null;
}
}
use of android.graphics.Canvas in project Lazy by l123456789jy.
the class BitmapUtil method saturation.
/**
* 饱和度处理
*
* @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;
}
use of android.graphics.Canvas in project Lazy by l123456789jy.
the class CreatQRCodeImg method addLogo.
/**
* 在二维码中间添加Logo图案
*/
private static Bitmap addLogo(Bitmap src, Bitmap logo) {
if (src == null) {
return null;
}
if (logo == null) {
return src;
}
//获取图片的宽高
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
if (srcWidth == 0 || srcHeight == 0) {
return null;
}
if (logoWidth == 0 || logoHeight == 0) {
return src;
}
//logo大小为二维码整体大小的1/5
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
} catch (Exception e) {
bitmap = null;
e.getStackTrace();
}
return bitmap;
}
use of android.graphics.Canvas in project Lazy by l123456789jy.
the class ImageProcessor method lumAndHueAndSaturation.
/**
* 亮度、色相、饱和度处理
* @param lumValue 亮度值
* @param hueValue 色相值
* @param saturationValue 饱和度值
* @return 亮度、色相、饱和度处理后的图片
*/
public Bitmap lumAndHueAndSaturation(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;
}
use of android.graphics.Canvas in project Lazy by l123456789jy.
the class ImageProcessor method saturation.
/**
* 饱和度处理
* @param saturationValue 新的饱和度值
* @return 改变了饱和度值之后的图片
*/
public Bitmap saturation(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(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
//将原图使用给定的画笔画到画布上
canvas.drawBitmap(bitmap, 0, 0, paint);
return newBitmap;
}
Aggregations