2011-05-17 110 views
1

我使用表面視圖來顯示我的自定義相機,但與原始相機相比,相機的視圖看起來比較舒展,但它被正確記錄。在android中的相機拉伸視圖?

我該如何解決這個問題?

我用下面的代碼,

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(); 
    } 
} 

回答