2011-06-15 66 views
2

其中我在我的申請中所使用的相機視圖是不一樣的本機的攝像頭,例如,本地相機視圖如下所示, enter image description here在android中展開相機視圖?

但視圖是不是在我的應用程序作爲相同,我使用surfaceview我與媒體錄像機專用相機拍攝視頻,在佈局我使用框架佈局,

<com.cdr.Vio.CamcorderView android:id="@+id/camcorder_preview" android:clickable="true" android:focusable="true" android:layout_height="wrap_content" android:layout_width="wrap_content"></com.cdr.Vio.CamcorderView> 

.. ..

<Button android:id="@+id/widget34" android:background="@drawable/camrecord" 
    android:layout_height="60dp" android:layout_width="60dp" 
    android:layout_gravity="right" android:layout_marginRight="20dp"> 
</Button> 
<Button android:id="@+id/widget33" android:background="@drawable/stoprecord" 
    android:layout_gravity="right" android:layout_height="60dp" 
    android:layout_width="60dp" android:layout_marginTop="-60dp" 
    android:layout_marginRight="20dp"> 
</Button> 

我試圖與預定義的屏幕高度和屏幕寬度的觀點,但似乎又有些什麼捉襟見肘,這裏是我的拉伸攝像機視圖, enter image description here

我怎麼能解決,如果有任何知道這個問題幫助我。

謝謝。

回答

0

看起來縱橫比已經消失了。 嘗試更改相機的preivew分辨率。

調用setPreviewSize關於相機參數並設置相機設備上的相機參數。重新開始預覽。

編輯:添加代碼

mCameraDevPara.setPreviewSize(PREVIEW_WIDTH, PREVIEW_HEIGHT); 
mCameraDev.setParameters(mCameraDevPara); 
mMediaRecoder.setCamera(mCameraDev); 

PREVIEW_WIDTHPREVIEW_HEIGHT應寬度和要設定預覽分辨率的高度。

+0

如何設置預覽大小MediaRecorder – Karthi 2011-06-15 07:06:48

+0

您需要設置'Camera'對象的預覽大小,然後通過'setCamera'方法的相機對象傳遞給'MediaRecorder'。簡單地說,您可以針對特定相機對象設置預覽分辨率,然後將該相機對象傳遞給媒體錄製器。還要確保您在xml中定義的表面視圖具有與預覽分辨率相同的寬度和高度。 – bluefalcon 2011-06-15 08:30:17

+0

由於有任何樣本......因爲它不適合我...... – Karthi 2011-06-15 09:29:24

1

最後,我發現了通過設置videEncodingBitRate,AudioEncodingBitRate,AudioSamplingRate等等來在android 2.1中記錄高質量視頻的代碼。使用這種方法,您可以爲視頻設置任何想要提供高質量視頻的屬性。

用於設置高品質和低品質參數是指當前頁,

http://www.andgps.com/20110410/camcorderprofile-predefined-camcorder-profile-settings-for-camcorder-applications

我用鹼Android 2.1版本用於產生高品質的視頻中的代碼如下所示。

recorder = new MediaRecorder(); 
Method[] methods = recorder.getClass().getMethods(); 

recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
recorder.setVideoFrameRate(24); 
recorder.setVideoSize(720, 480); 

for (Method method : methods) { 
    try { 
     if (method.getName().equals("setAudioChannels")) { 
      method.invoke(recorder, String.format("audio-param-number-of-channels=%d", 1)); 
     } else if (method.getName().equals("setAudioEncodingBitRate")) { 
      method.invoke(recorder, 12200); 
     } else if (method.getName().equals("setVideoEncodingBitRate")) { 
      method.invoke(recorder, 3000000); 
     } else if (method.getName().equals("setAudioSamplingRate")) { 
      method.invoke(recorder, 8000); 
     } else if (method.getName().equals("setVideoFrameRate")) { 
      method.invoke(recorder, 24); 
     } 
    } catch (IllegalArgumentException e) { 

     e.printStackTrace(); 
    } catch (IllegalAccessException e) { 

     e.printStackTrace(); 
    } catch (InvocationTargetException e) { 

     e.printStackTrace(); 
    } 
} 

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); 
相關問題