(1) 將一個位圖按照需求重畫一遍,畫後的獲得位圖與位圖的顯示幾乎同樣java
drawBitmap.(Bitmap bitmap,Rect src,Rect dst,Paint paint)
(2)在原有位圖的基礎上放縮原位圖,建立一個新的位圖canvas
CreateBitmap(Bitmap source,int x, int width, int height,Matrix m ,boolean filter)
(3)藉助Canvas的scale (float,sx,float,sy)方法,不過要注意此時的整個畫布都放縮了post
(4)藉助Matrix實現code
Bitmap bmp = BitmapFactory.decodeResource(getResource(),R.drawable.pic); Matrix matrix = new Matrix(); matrix.postScale(0.2f,0.2f); Bitmap dstbmp = Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix true); canvas.drawColor(Color.BLACK); canvas.drawBitmap(dstbmp,10,10,null);
Bitmap bmp = BitmapFactory.decodeResource(getResource(),R.drawable.pic); Matrix matrix = new Matrix(); matrix.postScale(0.8f,0.8f); matrix.postRotate(45); //多了這麼一句 Bitmap dstbmp = Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix true); canvas.drawColor(Color.BLACK); canvas.drawBitmap(dstbmp,10,10,null);