我需要將圖像(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