use of android.graphics.Bitmap in project ion by koush.
the class BitmapCallback method getBitmapSnapshot.
public static void getBitmapSnapshot(final Ion ion, final String transformKey, final ArrayList<PostProcess> postProcess) {
// don't do this if this is already loading
if (ion.bitmapsPending.tag(transformKey) != null)
return;
final BitmapCallback callback = new LoadBitmapBase(ion, transformKey, true);
Ion.getBitmapLoadExecutorService().execute(new Runnable() {
@Override
public void run() {
if (ion.bitmapsPending.tag(transformKey) != callback) {
// Log.d("IonBitmapLoader", "Bitmap cache load cancelled (no longer needed)");
return;
}
try {
File file = ion.responseCache.getFileCache().getFile(transformKey);
Bitmap bitmap = IonBitmapCache.loadBitmap(file, null);
if (bitmap == null)
throw new Exception("Bitmap failed to load");
BitmapInfo info = new BitmapInfo(transformKey, "image/jpeg", bitmap, null);
info.servedFrom = ResponseServedFrom.LOADED_FROM_CACHE;
if (postProcess != null) {
for (PostProcess p : postProcess) {
p.postProcess(info);
}
}
callback.report(null, info);
} catch (OutOfMemoryError e) {
callback.report(new Exception(e), null);
} catch (Exception e) {
callback.report(e, null);
try {
ion.responseCache.getFileCache().remove(transformKey);
} catch (Exception ex) {
}
}
}
});
}
use of android.graphics.Bitmap 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.Bitmap 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.Bitmap 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.Bitmap 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