[英]Camera preview and recording size
我正在將此庫用於視頻共享應用程序項目,並且正在使用CameraDemo_layout,並將com.commonsware.cwac.camera.CameraView尺寸的高度和寬度均設置為320dip。 但是,錄制的視頻似乎是按照手機屏幕的尺寸進行錄制的,因此看起來很不對勁。 您能否指導我完成設置視頻記錄的過程,以遵循照相機視圖組布局的尺寸。 謝謝。
我的活動:
public class RecordingActivity extends Activity implements
CameraHostProvider {私有DemoCamCameraFragment current = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recording);
current=new DemoCameraFragment();
getFragmentManager().beginTransaction()
.replace(R.id.container, current).commit();
}
@Override
public CameraHost getCameraHost() {
return(new SimpleCameraHost(this));
}
我的片段:
public class DemoCameraFragment extends CameraFragment {
android.hardware.Camera camera;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View content=inflater.inflate(R.layout.camera, container, false);
CameraView cameraView=(CameraView)content.findViewById(R.id.camera);
Log.d("daba", "the cameraview attrs: " + cameraView.getHeight() + " -- " + cameraView.getWidth());
setCameraView(cameraView);
// SimpleCameraHost.Builder builder = new SimpleCameraHost.Builder(getActivity());
// builder.useFullBleedPreview(false);
//
// setHost(builder.build());
final ImageButton record = (ImageButton) content.findViewById(R.id.record);
final ImageButton next = (ImageButton) content.findViewById(R.id.next);
next.setEnabled(false);
record.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(record.getTag().toString().equals("Hi!")){
try {
record();
record.setTag("By!");
record.setBackgroundColor(Color.DKGRAY);
next.setEnabled(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
try {
stopRecording();
record.setTag("Hi!");
record.setBackgroundColor(Color.TRANSPARENT);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(isRecording())
Toast.makeText(getActivity(), "Finish recording first", Toast.LENGTH_SHORT).show();
else{
Intent i = new Intent(getActivity(), VideoSetData.class);
getActivity().startActivity(i);
}
}
});
if(isRecording()){
}
return(content);
}
}
我的Camera.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.commonsware.cwac.camera.CameraView
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/cancel" />
<ImageButton
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/right" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/record"
android:tag="Hi!" >
</ImageButton>
</LinearLayout>
但是,錄制的視頻似乎是按照手機屏幕的尺寸進行錄制的,這使它看起來太不正確了
記錄的分辨率應與CameraView
的尺寸CameraView
。 錄制的分辨率應來自您使用setProfile()
對MediaRecorder
的配置。
setProfile()
是用來在CameraHost
在configureRecorderProfile()
SimpleCameraHost
使用其自己的算法來選擇配置文件。 您將需要SimpleCameraHost
子類,並重寫configureRecorderProfile()
以使用其他算法來選擇配置文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.