bitmap图片处理
?//放大缩小图片 ?
?? ?public static Bitmap zoomBitmap(Bitmap bitmap,int w,int h){ ?
?? ? ? ?int width = bitmap.getWidth(); ?
?? ? ? ?int height = bitmap.getHeight(); ?
?? ? ? ?Matrix matrix = new Matrix(); ?
?? ? ? ?float scaleWidht = ((float)w / width); ?
?? ? ? ?float scaleHeight = ((float)h / height); ?
?? ? ? ?matrix.postScale(scaleWidht, scaleHeight); ?
?? ? ? ?Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); ?
?? ? ? ?return newbmp; ?
?? ?} ?
?? ?//将Drawable转化为Bitmap ?
?? ? public static Bitmap drawableToBitmap(Drawable drawable){ ?
?? ? ? ? ? ?int width = drawable.getIntrinsicWidth(); ?
?? ? ? ? ? ?int height = drawable.getIntrinsicHeight(); ?
?? ? ? ? ? ?Bitmap bitmap = Bitmap.createBitmap(width, height, ?
?? ? ? ? ? ? ? ? ? ?drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 ?
?? ? ? ? ? ? ? ? ? ? ? ? ? ?: Bitmap.Config.RGB_565); ?
?? ? ? ? ? ?Canvas canvas = new Canvas(bitmap); ?
?? ? ? ? ? ?drawable.setBounds(0,0,width,height); ?
?? ? ? ? ? ?drawable.draw(canvas); ?
?? ? ? ? ? ?return bitmap; ?
?
?? ? ? ?}