读书人

bit地图图片处理

发布时间: 2012-09-28 00:03:35 作者: rapoo

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; ?

?

?? ? ? ?}

读书人网 >移动开发

热点推荐