2013-07-09 151 views

回答

1

This正是你所需要的。

// Returns an immutable bitmap from the specified subset of the source bitmap. 
static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) 



我真的不知道,如果(0,0)是左上角或中心,但我相信它的左上角。

* (0,0) 

*~~~~~~+===========+ 
'  '   | 
'  ' 200  | 
'  '   | 
+~~~~~~+   | 400 
| 100    | 
|     | 
|     | 
+==================+ 
     300 


如果这是真的那么中心:

x should be width /2 
y >>  height/2 

否则,如果它的左上角:

x should be width /2 - cropWidth/2 
y >>  height/2 - cropHeight/2 

两个场合是这样的。

* (150,200) 

+==================+ 
|     | 
|  +~~~~~~+  | 
|  '  '  | 
|  ' * '200 | 400 
|  '  '  | 
|  +~~~~~~+  | 
|  100  | 
+==================+ 
     300 
+0

得到了类似'newBitmap = Bitmap.createBitmap(oldBitmap,x,y,500,500);'。正如你所看到的,x和y缺失。我不知道如何计算它。 – Reinherd

+0

@SergiCastellsaguéMillán再次阅读我的答案。 –

0

600x600px

if(srcBmp.getWidth()>600 && srcBmp.getHeight()>600) 
    dstBmp = Bitmap.createBitmap(srcBmp, 
     srcBmp.getWidth()/2 - 600/2, 
     srcBmp.getHeight()/2 - 600/2, 
     600, 
     600); 

我改变从你给的链接代码,希望这个作品。