我使用表面视图来显示我的自定义相机,但是相机的视图与原始相机相比看起来很拉伸,但它被正确记录。
我该如何解决这个问题?
我使用以下代码
public class CamcorderView extends SurfaceView implements
SurfaceHolder.Callback {
MediaRecorder recorder;
SurfaceHolder holder;
String outputFile = "/sdcard/greVat.mp4";
Context c;
public CamcorderView(Context context, AttributeSet attrs) {
super(context, attrs);
c=context;
holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
}
public void surfaceCreated(SurfaceHolder holder) {
recorder.setOutputFile(path);
recorder.setPreviewDisplay(holder.getSurface());
if (recorder != null) {
try {
recorder.prepare();
} catch (IllegalStateException e) {
Log.e("IllegalStateException", e.toString());
} catch (IOException e) {
Log.e("IOException", e.toString());
}
}
}
public Surface getSurface()
{
return holder.getSurface();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
if(recorder!=null)
{
recorder.release();
recorder = null;
}
}
public void setOutputFile(String filename)
{
recorder.setOutputFile(path);
}
public String deleteVideoPath(){
return path;
}
public String startRecording()
{ recorder.setOutputFile(path);
recorder.start();
return videoName;
}
public String stopRecording()
{
recorder.stop();
recorder.release();
recorder=null;
return path;
}
public void release(){
recorder.release();
recorder=null;
}
public void init(){
recorder=new MediaRecorder();
}
}