use of android.graphics.PorterDuffXfermode in project android_frameworks_base by ResurrectionRemix.
the class ScrimView method setDrawAsSrc.
public void setDrawAsSrc(boolean asSrc) {
mDrawAsSrc = asSrc;
mPaint.setXfermode(new PorterDuffXfermode(mDrawAsSrc ? PorterDuff.Mode.SRC : PorterDuff.Mode.SRC_OVER));
invalidate();
}
use of android.graphics.PorterDuffXfermode in project AndroidSDK-RecipeBook by gabu.
the class Recipe051 method createReflectionBitmap.
public static Bitmap createReflectionBitmap(Bitmap src) {
// 元画像と反射画像のマージン
int margin = 4;
int width = src.getWidth();
int height = src.getHeight();
// 上下反転させるMatrix
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
// 元画像の下半分を反転したBitmapを生成
Bitmap reflection;
reflection = Bitmap.createBitmap(src, 0, height / 2, width, height / 2, matrix, true);
// 元画像と反射画像が合体した結果画像のBitmapを生成
// これはまだ空っぽ
Bitmap result;
result = Bitmap.createBitmap(width, height + height / 2, Config.ARGB_8888);
// キャンバスを使って
Canvas canvas;
canvas = new Canvas(result);
// 結果画像に元画像を書き込む
canvas.drawBitmap(src, 0, 0, null);
// 結果画像に反射画像を書き込む
canvas.drawBitmap(reflection, 0, height + margin, null);
// ここまでで反転画像と合体した状態
// ここからぼかし
Paint paint = new Paint();
// LinearGradientという直線方向のグラデーションを使います。
LinearGradient shader;
// だんだん透明になるグラデーションを作る
// 0x90ffffff(やや透明) -> 0x00FFFFFF(完全透明)
shader = new LinearGradient(0, height, 0, result.getHeight() + margin, 0x90ffffff, 0x00ffffff, TileMode.CLAMP);
// Shaderクラスを継承しているのでsetShaderでPaintにセットします。
paint.setShader(shader);
// 色の変換モードを指定
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// グラデーションを描画
canvas.drawRect(0, height, width, result.getHeight(), paint);
return result;
}
use of android.graphics.PorterDuffXfermode in project SmartAndroidSource by jaychou2012.
the class BitmapAjaxCallback method getRoundedCornerBitmap.
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
use of android.graphics.PorterDuffXfermode in project Lazy by l123456789jy.
the class ImageProcessor method reflection.
/**
* 倒影处理
* @param reflectionSpacing 原图与倒影之间的间距
* @return 加上倒影后的图片
*/
public Bitmap reflection(int reflectionSpacing, int reflectionHeight) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
/* 获取倒影图片,并创建一张宽度与原图相同,但高度等于原图的高度加上间距加上倒影的高度的图片,并创建画布。画布分为上中下三部分,上:是原图;中:是原图与倒影的间距;下:是倒影 */
//
Bitmap reflectionImage = reverseByVertical(bitmap);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, height + reflectionSpacing + reflectionHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
/* 将原图画到画布的上半部分,将倒影画到画布的下半部分,倒影与画布顶部的间距是原图的高度加上原图与倒影之间的间距 */
canvas.drawBitmap(bitmap, 0, 0, null);
canvas.drawBitmap(reflectionImage, 0, height + reflectionSpacing, null);
reflectionImage.recycle();
/* 将倒影改成半透明,创建画笔,并设置画笔的渐变从半透明的白色到全透明的白色,然后再倒影上面画半透明效果 */
Paint paint = new Paint();
paint.setShader(new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionSpacing, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP));
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawRect(0, height + reflectionSpacing, width, bitmapWithReflection.getHeight() + reflectionSpacing, paint);
return bitmapWithReflection;
}
use of android.graphics.PorterDuffXfermode in project Lazy by l123456789jy.
the class ImageProcessor method roundCorner.
/**
* 圆角处理
* @param pixels 角度,度数越大圆角越大
* @return 转换成圆角后的图片
*/
public Bitmap roundCorner(float pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
//创建一个同原图一样大小的矩形,用于把原图绘制到这个矩形上
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
//创建一个精度更高的矩形,用于画出圆角效果
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
//涂上黑色全透明的底色
canvas.drawARGB(0, 0, 0, 0);
//设置画笔的颜色为不透明的灰色
paint.setColor(0xff424242);
//用给给定的画笔把给定的矩形以给定的圆角的度数画到画布
canvas.drawRoundRect(rectF, pixels, pixels, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
//用画笔paint将原图bitmap根据新的矩形重新绘制
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
Aggregations