安卓图像传输只显示一部分图片 10C

安卓端传输到服务器的图片只显示一部分? private static String TAG = "MainActivity";
private Camera mCamera;
private SurfaceView mPreview;
private SurfaceHolder mHolder;

private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        File tempFile = new File("/sdcard/temp.jpg");
        try{
            FileOutputStream fos = new FileOutputStream(tempFile);
            fos.write(data);
            fos.close();





            new MyThread().start();
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }

    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mPreview = (SurfaceView) findViewById(R.id.preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);

}
public void  buttonCamera(View view){
    //onClick 事件
    // ==============  Camera
    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setPictureFormat(ImageFormat.JPEG);
    parameters.setPictureSize(480,320);
    parameters.setPictureSize(2560,720);
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    mCamera.autoFocus(new Camera.AutoFocusCallback(){
        @Override
        public void onAutoFocus(boolean success, Camera camera) {
            if (success){
                mCamera.takePicture(null,null,mPictureCallback);
            }
        }
    });
}

@Override
protected void onResume() {
    super.onResume();
    if (mCamera == null){
        mCamera = getCamera();
        if (mHolder != null){
            setStartPreview(mCamera,mHolder);
        }
    }
}

@Override
protected void onPause() {
    super.onPause();
    releaseCamera();
}

/**
 * 获取Camera对象
 * @return
 */
private Camera getCamera(){
    Camera camera;
    try {
        camera = Camera.open();
    }catch (Exception e){
        camera = null;
        e.printStackTrace();
    }
    return camera;
}

/**
 * 开始预览相机内容
 */
private void setStartPreview(Camera camera,SurfaceHolder holder){
    try{
        camera.setPreviewDisplay(holder);
        // 将系统Camera预览角度进行调整
        camera.setDisplayOrientation(90);
        camera.startPreview();
    }catch (IOException e){
        e.printStackTrace();
    }

}

/**
 * 释放相机资源
 */
private void releaseCamera(){
    if (mCamera != null){
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();
        mCamera.release();
        mCamera = null;
    }

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问