Android:如何选择图像的一部分?

问题描述:

在我的申请。有部分选择的公寓块。在那里有一个A和B块。所以我想从单个图像中选择A或B块。图片是enter image description hereAndroid:如何选择图像的一部分?

有什么办法可以做到这一点?

使用BitMap概念。将完整图像转换为位图,裁剪基于(x,y)位置的位图。

Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.myimage); 

Bitmap cropbitmap=Bitmap.createBitmap(bitmap, xpoint,ypoint,width, height); 
//default android method createBitmap(Bitmap source, int x, int y, int width, int height) 

等简单的方式利用图书馆这样从GitHub

我想你可以使用getLocationOnScreen()并硬编码你想要的值。如果用户点击图片的某个部分,会提示一个响应,如果他们点击其他地方,则会提示另一个响应。更多信息Android: How do I get the x y coordinates within an image/ImageView?