2013-03-18 202 views
1

enter image description here如何將像素(手機的顯示寬度)轉換爲毫秒(毫秒)?

我想使用從文件中提取的字節數組並嘗試將其設置爲查找欄的背景來繪製錄製聲音的圖形。我已經成功畫出了上面顯示的數額,但它不準確。爲了獲得精確的圖形,我需要將像素轉換爲毫秒。實際上,在搜索欄中完成的最大和進度更新以毫秒爲單位。但是,我使用循環內顯示寬度的像素繪製圖形。因此,如果我可以將像素轉換爲毫秒並繪製圖形,毫秒可以做出一個準確的progreesbargraph(希望如此)。

因此,任何一個可以幫助我將像素轉換爲毫秒???如果手機的顯示寬度是480,我需要將480轉換爲毫秒,任何方式??幫助我!!!

width=number of pixels of display width 
for (int iPixel = 0; iPixel < width; iPixel++) 
      { 
        { 
      int start = (int) ((float) iPixel * ((float) width)); 
      int end = (int) ((float) (iPixel + 1) * ((float) width)); 

      for (int i = start; i < end; i++) { 
      //code to find the pixel to draw 
      } 

    //code to draw in canvas 
     } 
+0

以毫秒爲單位的最大長度是多少?我猜歌曲的長度。所以最大毫秒和最大像素之間的比例。 – 2013-03-18 11:41:22

+0

在錄製或保存錄制文件後執行此操作嗎? – AwadKab 2013-03-18 11:42:20

+0

@AwadKab保存文件後已完成 – 2013-03-18 11:46:43

回答

1

試試這個:

total width(unit)/total file length(milliseconds) = result(unit/milliseconds) 

然後result移動你的平局每milliseconds

編輯

我的建議是:

1集搜索欄最大= 100; min = 0;

2-轉換媒體lenght百分數通過使用這種方法:

public int getProgressPercentage(long currentDuration, long totalDuration){ 
     Double percentage = (double) 0; 

     long currentSeconds = (int) (currentDuration); 
     long totalSeconds = (int) (totalDuration); 

     // calculating percentage 
     percentage =(((double)currentSeconds)/totalSeconds)*100; 

     // return percentage 
     return percentage.intValue(); 
    } 

然後使用此persent在搜索欄等setProgress(getProgressPercentage(long currentDuration, long totalDuration));

3-器具OnSeekBarChangeListener並使用其progress參數提請圖表:

@Override 
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { 
    // Here use int progress to draw graph. It is percent 
    // Current width = 400*percent/100 = result; 
    // draw until result value; 
} 

/** 
* When user starts moving the progress handler 
* */ 
@Override 
public void onStartTrackingTouch(SeekBar seekBar) {} 

/** 
* When user stops moving the progress hanlder 
* */ 
@Override 
public void onStopTrackingTouch(SeekBar seekBar) {} 

希望這對你有所幫助。

+0

這不起作用,總寬度是480,總持續時間是18947,所以計算結果是這樣的結果= 480/18947,並且它的循環結果沒有值。沒有圖形繪製.... – 2013-03-18 12:12:19

+0

請參閱我的建議。 – AwadKab 2013-03-18 12:45:51

+0

實際上我並沒有在運行時繪製圖形,我把這個文件保存在SD卡上。最初我讀取字節,使用畫布繪製圖形並將其設置爲seekbar的背景。這是場景。 – 2013-03-19 05:14:55