Browse Source

优化USB Camera分辨率切换

main
jiangdongguo 7 years ago
parent
commit
b0ac2d1c0c
  1. 4
      app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java
  2. 9
      libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java

4
app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java

@ -89,15 +89,15 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
if(! isConnected) { if(! isConnected) {
showShortMsg("连接失败,请检查分辨率参数是否正确"); showShortMsg("连接失败,请检查分辨率参数是否正确");
} }
showShortMsg("连接成功");
} }
// 与USB设备断开连接 // 与USB设备断开连接
@Override @Override
public void onDisConnectDev(UsbDevice device) { public void onDisConnectDev(UsbDevice device) {
showShortMsg("连接失败");
} }
}; };
private FileOutputStream fos;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {

9
libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java

@ -91,6 +91,8 @@ public class USBCameraManager{
if(listener != null){ if(listener != null){
listener.onDettachDev(device); listener.onDettachDev(device);
} }
// 释放资源
release();
} }
// 当连接到USB Camera时,被回调 // 当连接到USB Camera时,被回调
@ -116,8 +118,6 @@ public class USBCameraManager{
if(listener != null){ if(listener != null){
listener.onDisConnectDev(device); listener.onDisConnectDev(device);
} }
// 关闭摄像头
closeCamera();
} }
@Override @Override
@ -131,9 +131,12 @@ public class USBCameraManager{
// 切换分辨率 // 切换分辨率
public void updateResolution(Activity activity, CameraViewInterface cameraView, int width, int height, final OnPreviewListener mPreviewListener){ public void updateResolution(Activity activity, CameraViewInterface cameraView, int width, int height, final OnPreviewListener mPreviewListener){
// 如果分辨率无变化,则无需重启Camera
if(previewWidth == width && previewHeight == height){
return;
}
this.previewWidth = width; this.previewWidth = width;
this.previewHeight = height; this.previewHeight = height;
// 关闭摄像头 // 关闭摄像头
closeCamera(); closeCamera();
// 释放CameraHandler占用的相关资源 // 释放CameraHandler占用的相关资源

Loading…
Cancel
Save