Bitmap resizedBitmap;
int srcw = bitmapOrg.getWidth();
int srch = bitmapOrg.getHeight();
// 如果长宽小于生成的目标图片,直接返回图片
if (srcw <= dstw && srch <= dsth)
{
return bitmapOrg;
}
// else if (srcw > dstw && srch < dsth)
// {
//
// resizedBitmap
//
//
// }
float scaleWidth = ((float) dstw) / srcw;
float scaleHeight = ((float) dsth) / srch;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the Bitmap
matrix.postScale(scaleWidth, scaleHeight);
// if you want to rotate the Bitmap
// matrix.postRotate(45);
// recreate the new Bitmap
resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, srcw, srch,
matrix, true);
bitmapOrg.recycle();
// make a Drawable from Bitmap to allow to set the Bitmap
// to the ImageView, ImageButton or what ever
return resizedBitmap;
}
/**
*
* [ 图像圆角处理]<BR>
* [功能详细描述]
*
* @param bitmap
* @param roundPX
* @return
*/
public static Bitmap getRCB(Bitmap bitmap, float roundPX) //RCB means Rounded Corner Bitmap
{
Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(dstbmp);
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);
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 dstbmp;
}