2012-05-18 26 views
0

我需要在視圖中顯示非常大的圖像(例如8000x8000),以允許用戶放大和縮小。Android中的多點觸控手勢和圖像

我檢查了幾個選項來檢測用戶觸摸並根據該圖像進行轉換。例如:

How to use Multi-touch in Android

和其他人使用手勢/觸摸探測器等

的問題是,沒有人照顧的位圖的大小和更多鈔票崩潰,因爲位圖不適合在記憶中。

所以我在找的是如何實現像Android的畫廊。沒有失去質量時,圖像放大,當然沒有崩潰

任何想法?完整,有效的答案將取決於答案

+0

你可以試試[Android源碼](http://stackoverflow.com/a/9728899/942821)(4.0)。 – 2012-05-18 13:31:39

+1

http://stackoverflow.com/questions/4996470/load-large-image-from-server-on-android http://stackoverflow.com/questions/7834132/loading-big-image-to-bitmap-in -android 這些鏈接可能會幫助你! –

回答

2

試着只顯示縮放的位圖子集並儘可能少地解碼。我管理類似的東西。這些是幫助我很多的代碼片段:

要計算所需的所有值(例如縮放因子,像素數量等),可以使用inJustDecodeBounds獲取位圖的大小而不分配任何內存。:

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

僅解碼位圖的一個子集使用:

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

要創建縮放位圖:

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

繪製位圖的一個子集:

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

編輯: 我忘記提到這snipplet創建縮放圖像。爲了節省內存,這是你想要什麼:

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

由於inSampleSize必須是我用createScaledBitmap調整位圖多一點的整數。

1

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

可能的複雜性和質量達到300分被bountried?

現在這些網站已經關閉了,所以它最終甚至可能與您無關,但我認爲我應該發佈它。

「變焦控制(控件)聽OnTouch事件來處理平移」

最後:

https://github.com/MikeOrtiz/TouchImageView

^^可能是你尋找什麼作爲據我所知2.0+

失敗,web視圖和加載文件就像那樣。

+0

感謝您的回答。我稍後會檢查第一個鏈接,但第二個鏈接檢測觸摸並重新縮放圖像,但不關心內存管理。你可以檢查試圖加載一個非常大的圖像 – Addev