12. 获取可用内存的最大值(App使用内存超出这个值会引起OutOfMemory异常):
- private int getMaxMemoryForApp() { int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
- return maxMemory; }
13.将图片裁剪成圆圈:
- /** * 将Bitmap处理为圆形的图片
- * @param bitmap 处理之前的位图 * @return 处理之后的位图
- */ public static Bitmap circlePic(Bitmap bitmap){
- int width = bitmap.getWidth(); int height = bitmap.getHeight();
- int r = width < height ? width/2:height/2;//圆的半径,取宽和高中较小的,以便于显示没有空白 Bitmap outBitmap = Bitmap.createBitmap(r*2, r*2, Bitmap.Config.ARGB_8888);//创建一个刚好2r大小的Bitmap
- Canvas canvas = new Canvas(outBitmap); final int color =0xff424242;
- final Paint paint = new Paint(); /**
- * 截取图像的中心的一个正方形,用于在原图中截取 * 坐标如下:
- * 1.如果 w < h , 左上坐标(0, (h-w)/2) , 右上坐标(w, (h+w)/2) 偏移10 * 2.如果 w > h , 左上坐标((w-h)/2, 0) , 右上坐标((w+h)/2, h) 偏移10
- */ final Rect rect = new Rect( width < height ? 0 : (width-height)/2, width < height ? (height-width)/2 - 10 : -10,










