use of android.graphics.PorterDuffXfermode in project Lazy by l123456789jy.
the class BitmapUtil method createReflectionBitmap.
/**
* 获得带倒影的图片方法
*
* @param bitmap 源Bitmap
* @return 带倒影的Bitmap
*/
public static Bitmap createReflectionBitmap(Bitmap bitmap) {
final int reflectionGap = 4;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(bitmap, 0, 0, null);
Paint deafalutPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
// Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
use of android.graphics.PorterDuffXfermode in project KJFrameForAndroid by kymjs.
the class RoundImageView method getCroppedRoundBitmap.
/**
* 获取裁剪后的圆形图片
*
* @param radius
* 半径
* @param bmp
* 要被裁减的图片
*/
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
Bitmap scaledSrcBmp;
int diameter = radius * 2;
// 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
int squareWidth = 0, squareHeight = 0;
int x = 0, y = 0;
Bitmap squareBitmap;
if (bmpHeight > bmpWidth) {
// 高大于宽
squareWidth = squareHeight = bmpWidth;
x = 0;
y = (bmpHeight - bmpWidth) / 2;
// 截取正方形图片
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
} else if (bmpHeight < bmpWidth) {
// 宽大于高
squareWidth = squareHeight = bmpHeight;
x = (bmpWidth - bmpHeight) / 2;
y = 0;
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
} else {
squareBitmap = bmp;
}
if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
} else {
scaledSrcBmp = squareBitmap;
}
Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(scaledSrcBmp.getWidth() / 2, scaledSrcBmp.getHeight() / 2, scaledSrcBmp.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
// 回收资源
// bmp.recycle();
// squareBitmap.recycle();
// scaledSrcBmp.recycle();
bmp = null;
squareBitmap = null;
scaledSrcBmp = null;
return output;
}
use of android.graphics.PorterDuffXfermode in project Talon-for-Twitter by klinker24.
the class ImageUtils method getSizedCircle.
public static Bitmap getSizedCircle(Bitmap currentImage, Context context, int dp) {
int scale = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
if (currentImage == null) {
return null;
}
if (currentImage.getWidth() >= currentImage.getHeight()) {
currentImage = Bitmap.createBitmap(currentImage, currentImage.getWidth() / 2 - currentImage.getHeight() / 2, 0, currentImage.getHeight(), currentImage.getHeight());
} else {
currentImage = Bitmap.createBitmap(currentImage, 0, currentImage.getHeight() / 2 - currentImage.getWidth() / 2, currentImage.getWidth(), currentImage.getWidth());
}
Bitmap output;
try {
output = Bitmap.createBitmap(scale, scale, Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError e) {
return null;
}
Canvas canvas = new Canvas(output);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
Rect rect = new Rect(0, 0, scale, scale);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(scale / 2, scale / 2, (scale / 2) - (scale / 25), paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
try {
canvas.drawBitmap(currentImage, null, rect, paint);
} catch (Exception e) {
// bitmap is null i guess
}
ResourceHelper helper = new ResourceHelper(context, "com.klinker.android.twitter");
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(helper.getDimension("contact_picture_border"));
try {
TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.circle_border });
int resource = a.getResourceId(0, 0);
a.recycle();
paint.setColor(context.getResources().getColor(resource));
} catch (Exception e) {
paint.setColor(helper.getColor("circle_outline_dark"));
}
canvas.drawCircle(scale / 2, scale / 2, (scale / 2) - (scale / 25), paint);
return resizeImage(context, output, dp);
}
use of android.graphics.PorterDuffXfermode in project GreenDroid by cyrilmottier.
the class MaskImageProcessor method init.
private void init() {
mFillPaint.setColor(Color.RED);
mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
}
use of android.graphics.PorterDuffXfermode in project Signal-Android by WhisperSystems.
the class CanvasView method createPaint.
/**
* This method creates the instance of Paint.
* In addition, this method sets styles for Paint.
*
* @return paint This is returned as the instance of Paint
*/
private Paint createPaint() {
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(this.paintStyle);
paint.setStrokeWidth(this.paintStrokeWidth);
paint.setStrokeCap(this.lineCap);
// fixed
paint.setStrokeJoin(Paint.Join.MITER);
// for Text
if (this.mode == Mode.TEXT) {
paint.setTypeface(this.fontFamily);
paint.setTextSize(this.fontSize);
paint.setTextAlign(this.textAlign);
paint.setStrokeWidth(0F);
}
if (this.mode == Mode.ERASER) {
// Eraser
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
paint.setARGB(0, 0, 0, 0);
// paint.setColor(this.baseColor);
// paint.setShadowLayer(this.blur, 0F, 0F, this.baseColor);
} else {
// Otherwise
paint.setColor(this.paintStrokeColor);
paint.setShadowLayer(this.blur, 0F, 0F, this.paintStrokeColor);
paint.setAlpha(this.opacity);
}
return paint;
}
Aggregations