android bitmap缩放失真,android中bitmap缩放和阴影效果
android中bitmap缩放和阴影效果1.缩放/*** zoom bitmap to certain size** @param bitmap* @param width* @param height* @return*/public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) {if (bitmap == nu
android中bitmap缩放和阴影效果
1.缩放
/**
* zoom bitmap to certain size
*
* @param bitmap
* @param width
* @param height
* @return
*/
public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) {
if (bitmap == null) {
return null;
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix matrix = new Matrix();
float scaleWidth = ((float) width / w);
float scaleHeight = ((float) height / h);
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
return newbmp;
}
2. 阴影
/**
* add shadow to bitmap
*
* @param originalBitmap
* @return
*/
private Bitmap drawImageDropShadow(Bitmap originalBitmap) {
BlurMaskFilter blurFilter = new BlurMaskFilter(1,
BlurMaskFilter.Blur.NORMAL);
Paint shadowPaint = new Paint();
shadowPaint.setAlpha(50);
shadowPaint.setColor(activity.getResources()
.getColor(R.color.solid_red));
shadowPaint.setMaskFilter(blurFilter);
int[] offsetXY = new int[2];
Bitmap shadowBitmap = originalBitmap
.extractAlpha(shadowPaint, offsetXY);
Bitmap shadowImage32 = shadowBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(shadowImage32);
c.drawBitmap(originalBitmap, offsetXY[0], offsetXY[1], null);
return shadowImage32;
}
摘自 fhy_2008的专栏
补充:移动开发 , Android ,
更多推荐
所有评论(0)