本文介绍了闪光灯切换按钮崩溃机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MainActivity
btnFlash.setOnClickListener(新OnClickListener()
{
@覆盖
公共无效的onClick(查看arg0中)
{
Toast.makeText(背景下,闪光翻转,Toast.LENGTH_LONG).show();
如果(相机preview.isFlashOn)
{
相机preview.FlashOff(摄像头);
相机preview.isFlashOn = FALSE;
}
其他
{
相机preview.isFlashOn = TRUE;
相机preview.FlashOn(摄像头);
}
}
});
相机preVIEW
公共静态布尔isFlashOn = FALSE; //
公共静态无效FlashOn(相机mCamera)
{
//获取相机PARAMS定制
Camera.Parameters参数= mCamera.getParameters();
//检查是否设备支持自动闪光,如果是,那么设置
//自动闪光
名单<字符串> flashModes = parameters.getSupportedFlashModes();
如果(flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
否则,如果(flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
}
mCamera.setParameters(参数);
mCamera.start preVIEW();
}
公共静态无效间断(flashoff)(相机mCamera)
{
//获取相机PARAMS定制
Camera.Parameters参数= mCamera.getParameters();
//检查是否设备支持自动闪光,如果是,那么设置
//自动闪光
名单<字符串> flashModes = parameters.getSupportedFlashModes();
如果(flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
}
mCamera.setParameters(参数);
mCamera.start preVIEW();
}
崩溃报告。
me_idx 0,码流类型9
W / ActivityManager(973):活动暂停超时ActivityRecord {45328828 U0
aus.xray.cam / .MainActivity2 T153 F}
D /毫米相机INTF(9138):mm_stream_read_msm_frame:VIDIOC_DQBUF buf_index 6,FRA
me_idx 840,码流类型1
I / mm的摄像头(473):mct_pipeline_process_set:命令= 8000013
I / mm的摄像头(473):pproc_module_handle_reprocess_offline:1318输入BUF FD 126
4型大小462848
D /毫米相机INTF(9138):mm_stream_read_msm_frame:VIDIOC_DQBUF buf_index 0,FRA
me_idx 0,码流类型9
D / CustomizationProcess(3778):dismissCustomizationDialog:真
I /窗口管理器(973):画面冻结+ 307ms由于窗口{44e24b48 U0 Statu
SBAR}
D /毫米相机INTF(9138):mm_stream_read_msm_frame:VIDIOC_DQBUF buf_index 0,FRA
me_idx 841,码流类型1
I / mm的摄像头(473):mct_pipeline_process_set:命令= 8000013
I / mm的摄像头(473):pproc_module_handle_reprocess_offline:1318输入BUF FD 120
4型大小462848
D /毫米相机INTF(9138):mm_stream_read_msm_frame:VIDIOC_DQBUF buf_index 1,FRA
me_idx 0,码流类型9
^ C
C:\ ADB>
解决方案
在木库的要求。我回答了我的自我。用于切换闪光灯
flashBtn.setOnClickListener(新OnClickListener()
{
@覆盖
公众的onClick(视图查看)
{
如果(cameraView!= NULL)// cameraView为相机preview.class
{
如果(cameraView.isFlashOn()&安培;&安培; isFlashRunning)
{
cameraView.FlashOff(照相机);
isFlashRunning = FALSE;
}
其他
{
cameraView.FlashOn(照相机);
isFlashRunning = TRUE;
}
}
});
并FlashOn和间断(flashoff)方法
公共无效FlashOn(相机mCamera)将抛出RemoteException
{
//获取相机PARAMS定制
Camera.Parameters参数= mCamera.getParameters();
//检查是否设备支持自动闪光,如果是,那么设置
//自动闪光
名单<字符串> flashModes = parameters.getSupportedFlashModes();
如果(flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
isFlashOn = TRUE;
}
否则,如果(flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
isFlashOn = TRUE;
}
mCamera.setParameters(参数);
mCamera.start preVIEW();
//mCamera.autoFocus(null); //可能这是问题
}
公共无效间断(flashoff)(相机mCamera)将抛出RemoteException
{
//获取相机PARAMS定制
Camera.Parameters参数= mCamera.getParameters();
//检查是否设备支持自动闪光,如果是,那么设置
//自动闪光
名单<字符串> flashModes = parameters.getSupportedFlashModes();
如果(flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
isFlashOn = FALSE;
}
mCamera.setParameters(参数);
mCamera.start preVIEW();
}
MainActivity
btnFlash.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
Toast.makeText(context, "Flash is toggled", Toast.LENGTH_LONG).show();
if(CameraPreview.isFlashOn)
{
CameraPreview.FlashOff(camera);
CameraPreview.isFlashOn = false;
}
else
{
CameraPreview.isFlashOn = true;
CameraPreview.FlashOn(camera);
}
}
});
CameraPreview
public static boolean isFlashOn =false; //
public static void FlashOn(Camera mCamera)
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();
// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
else if (flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
}
mCamera.setParameters(parameters);
mCamera.startPreview();
}
public static void FlashOff(Camera mCamera)
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();
// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
}
mCamera.setParameters(parameters);
mCamera.startPreview();
}
Crash Report.
me_idx 0, stream type 9
W/ActivityManager( 973): Activity pause timeout for ActivityRecord{45328828 u0
aus.xray.cam/.MainActivity2 t153 f}
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 6, fra
me_idx 840, stream type 1
I/mm-camera( 473): mct_pipeline_process_set:command=8000013
I/mm-camera( 473): pproc_module_handle_reprocess_offline:1318 input buf fd 126
type 4 size 462848
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 0, fra
me_idx 0, stream type 9
D/CustomizationProcess( 3778): dismissCustomizationDialog:true
I/WindowManager( 973): Screen frozen for +307ms due to Window{44e24b48 u0 Statu
sBar}
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 0, fra
me_idx 841, stream type 1
I/mm-camera( 473): mct_pipeline_process_set:command=8000013
I/mm-camera( 473): pproc_module_handle_reprocess_offline:1318 input buf fd 120
type 4 size 462848
D/mm-camera-intf( 9138): mm_stream_read_msm_frame: VIDIOC_DQBUF buf_index 1, fra
me_idx 0, stream type 9
^C
C:\adb>
解决方案
At the request of muku. I answered it my self. for toggling flash
flashBtn.setOnClickListener(new OnClickListener()
{
@Override
public onClick(View view)
{
if(cameraView!=null)//cameraView is the CameraPreview.class
{
if(cameraView.isFlashOn() && isFlashRunning)
{
cameraView.FlashOff(camera);
isFlashRunning = false;
}
else
{
cameraView.FlashOn(camera);
isFlashRunning = true;
}
}
});
And FlashOn and FlashOff methods are
public void FlashOn(Camera mCamera) throws RemoteException
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();
// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH))
{
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
isFlashOn = true;
}
else if (flashModes.contains(Parameters.FLASH_MODE_ON))
{
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
isFlashOn = true;
}
mCamera.setParameters(parameters);
mCamera.startPreview();
//mCamera.autoFocus(null); // may be this is problem
}
public void FlashOff(Camera mCamera) throws RemoteException
{
// Get Camera Params for customisation
Camera.Parameters parameters = mCamera.getParameters();
// Check Whether device supports AutoFlash, If you YES then set
// AutoFlash
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_OFF))
{
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
isFlashOn = false;
}
mCamera.setParameters(parameters);
mCamera.startPreview();
}
这篇关于闪光灯切换按钮崩溃机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!