我需要将图像(ImageViewer)分成块,并为它们分配onClick事件侦听器。对于划分的形象,我用下面的代码:Android:如何将ImageView分成块并将它们分配给ClickClickListener
private void splitImage(ImageView image, int rows, int cols) {
//For height and width of the small image chunks
int chunkHeight,chunkWidth;
//To store all the small image chunks in bitmap format in this list
ArrayList<Bitmap> chunkedImages = new ArrayList<Bitmap>(rows * cols);
//Getting the scaled bitmap of the source image
BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
Bitmap bitmap = drawable.getBitmap();
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), true);
chunkHeight = bitmap.getHeight()/rows;
chunkWidth = bitmap.getWidth()/cols;
//xCoord and yCoord are the pixel positions of the image chunks
int yCoord = 0;
for(int x=0; x<rows; x++){
int xCoord = 0;
for(int y=0; y<cols; y++){
chunkedImages.add(Bitmap.createBitmap(scaledBitmap, xCoord, yCoord, chunkWidth, chunkHeight));
xCoord += chunkWidth;
}
yCoord += chunkHeight;
}
}
但有了这个功能只有我得到位图的数组,他们不接受OnClickListener。我所做的是用大块重建图像,并能够放大所选块。
有什么想法?
在此先感谢。
怎么样设置ImageView的地方你想要显示块到OnTouchListener并从触摸获取x,y坐标?这应该是可能的.... – Opiatefuchs 2013-04-22 11:18:16