首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

bit地图图片处理

2012-09-28 
bitmap图片处理?//放大缩小图片 ??? ?public static Bitmap zoomBitmap(Bitmap bitmap,int w,int h){ ???

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

?

?? ? ? ?}

热点排行