0

ユーザーがズームインおよびズームアウトできるように、ビューに非常に大きな画像 (たとえば 8000x8000) を表示する必要があります。

ユーザーのタッチを検出し、それに応じて画像を変換するためのいくつかのオプションを確認しました。例えば:

Android でマルチタッチを使用する方法

その他、ジェスチャー/タッチ検出器などを使用しています。

問題は、ビットマップがメモリに収まらないため、それらのどれもビットマップのサイズを処理せず、クラッシュする可能性があることです。

だから私が探しているのは、Android のギャラリーのようにそれを実装する方法です。画像が拡大されたときに品質を失うことなく、もちろんクラッシュすることもありません

何か案は?完全で有効な回答には、回答の複雑さと質に応じて最大 300 ポイントが与えられます。

4

2 に答える 2

2

Try showing only a scaled subset of the bitmap and decode as few as possible. I managed something similar to this. These are the code snippets which helped me a lot:

To calculate all values you need (e.g. scale factor, number of pixels etc.) you can use inJustDecodeBounds to get the size of the bitmap without allocating any memory.:

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, opt);
int width = opt.outWidth;
int height = opt.outHeight;

To decode only a subset of a bitmap use this:

Bitmap.createBitmap(
    source, 
    xCoordinateOfFirstPixel, 
    yCoordinateOfFirstPixel, 
    xNumberOfPixels, 
    yNumberOfPixels
);

To create a scaled bitmap:

Bitmap.createScaledBitmap(
    source, 
    dstWidth, 
    dstHeight, 
    filter
);

To draw a subset of a bitmap:

Canvas.drawBitmap(
    source, 
    new Rect(
        subsetLeft, 
        subsetTop, 
        subsetRight, 
        subsetBottom
    ), 
    new Rect(0,0,dstWidth, dstHeight), 
        paint
);

Edit: I forget to mentioned this snipplet for creating scaled images. To save memory this is what you want:

BitmapFactory.Options opt = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap scaledBitmap = BitmapFactory.decodeFile(path, opt);

Since inSampleSize must be an integer I used createScaledBitmap to adjust the bitmap a bit more.

于 2012-05-18T18:07:42.993 に答える
1

http://www.anddev.org/large_image_scrolling_using_low_level_touch_events-t11182.html

もしかして?

現時点ではサイトがダウンしているので、最終的には関係ないかもしれませんが、投稿する必要があると思いました.

また

" ZOOM CONTROL (ウィジェット) OnTouch イベントをリッスンして、パンを処理します"

最後に:

https://github.com/MikeOrtiz/TouchImageView

^^ 私が知る限り、まさにあなたが探しているものかもしれません 2.0+

それに失敗した場合は、webview を開き、そのようにファイルをロードします。

于 2012-05-18T12:37:56.677 に答える