增加生成倒影图片方法
This commit is contained in:
parent
d0a24e3096
commit
6a1f86561b
|
@ -14,6 +14,7 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Color;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
|
@ -21,6 +22,7 @@ import android.graphics.PorterDuff.Mode;
|
|||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader.TileMode;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
|
@ -352,6 +354,37 @@ public class ToolPicture {
|
|||
return newbm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得倒影的图片
|
||||
* @param bitmap 原始图片
|
||||
* @return 带倒影的图片
|
||||
*/
|
||||
public static Bitmap makeReflectionImage(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);
|
||||
|
||||
Paint deafalutPaint = new Paint();
|
||||
Canvas canvas = new Canvas(bitmapWithReflection);
|
||||
canvas.drawBitmap(bitmap, 0, 0, null);
|
||||
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);
|
||||
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
|
||||
canvas.drawRect(0,height,width,bitmapWithReflection.getHeight()+reflectionGap,paint);
|
||||
|
||||
return bitmapWithReflection;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码图片
|
||||
* @param width 验证码宽度
|
||||
|
|
Loading…
Reference in New Issue