public Bitmap addRightShadow(Bitmap mSourceBM,int mShadowWidth,int[] mBackShadowColors) {
Bitmap newbm = Bitmap.createBitmap(mSourceBM.getWidth()+mShadowWidth, mSourceBM.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(newbm);
canvas.drawBitmap(mSourceBM, 0, 0, null);
mBackShadowDrawableLR = new GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT, mBackShadowColors);
mBackShadowDrawableLR.setGradientType(GradientDrawable.LINEAR_GRADIENT);
mBackShadowDrawableLR.setBounds(newbm.getWidth()-mShadowWidth, 0, newbm.getWidth() , newbm.getHeight());
mBackShadowDrawableLR.draw(canvas);
return newbm;
}
参数说明:
Bitmap mSourceBM:源图片;
int mShadowWidth:右边阴影的宽度,所以最终创建出来的图片会比源图宽mShadowWidth;
int[] mBackShadowColors:右边渐变颜色,例如new int[] { 0xF0AAAAAA , 0x10AAAAAA};。