2

画像 (ImageViewer) をチャンクに分割し、onClick イベント リスナーに割り当てる必要があります。画像を分割するには、次のコードを使用します。

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 を受け入れません。私がしているのは、チャンクで画像を再構築し、選択したチャンクを拡大できるようにすることです。

何か案が?

前もって感謝します。

4

3 に答える 3

0

そして、実際に画像を分割する必要がありますか? OnTouchListener画像全体に on を設定するだけです。その中から、タッチイベントの座標を取得できます。次に、いくつかの計算を行うと、画像のどの部分をズームするかがわかります。

于 2013-04-22T11:20:16.320 に答える
0

グリッド ビューを使用して画像のチャンクを作成し、onClickListener を設定できます。

于 2013-04-22T11:16:40.737 に答える