- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我使用 this 创建了一个自定义相机应用程序源代码,但在少数设备上(如高分辨率设备)我得到:
RuntimeException setParameters failed
我正面临这个异常(exception),因为:
params.setPictureSize(1200, 900);
我注意到,如果我使用 (1600, 1200)
而不是 (1200, 900)
那么我就不会遇到这样的问题
日志:
11-07 11:45:20.630: E/AndroidRuntime(3827): FATAL EXCEPTION: main
11-07 11:45:20.630: E/AndroidRuntime(3827): java.lang.RuntimeException: Unable to resume activity {pl.gatti.dgcam/pl.gatti.dgcam.DgCamActivity}: java.lang.RuntimeException: setParameters failed
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2825)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2854)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2318)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread.access$600(ActivityThread.java:144)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.os.Looper.loop(Looper.java:152)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread.main(ActivityThread.java:5132)
11-07 11:45:20.630: E/AndroidRuntime(3827): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 11:45:20.630: E/AndroidRuntime(3827): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 11:45:20.630: E/AndroidRuntime(3827): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-07 11:45:20.630: E/AndroidRuntime(3827): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-07 11:45:20.630: E/AndroidRuntime(3827): at dalvik.system.NativeStart.main(Native Method)
11-07 11:45:20.630: E/AndroidRuntime(3827): Caused by: java.lang.RuntimeException: setParameters failed
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.hardware.Camera.native_setParameters(Native Method)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.hardware.Camera.setParameters(Camera.java:1490)
11-07 11:45:20.630: E/AndroidRuntime(3827): at pl.gatti.dgcam.DgCamActivity.createCamera(DgCamActivity.java:124)
11-07 11:45:20.630: E/AndroidRuntime(3827): at pl.gatti.dgcam.DgCamActivity.onResume(DgCamActivity.java:163)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.Activity.performResume(Activity.java:5182)
11-07 11:45:20.630: E/AndroidRuntime(3827): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2815)
代码:
private void createCamera() {
// Create an instance of Camera
mCamera = getCameraInstance();
// Setting the right parameters in the camera
Camera.Parameters params = mCamera.getParameters();
params.setPictureSize(1200, 900);
params.setPictureFormat(PixelFormat.JPEG);
params.setJpegQuality(85);
mCamera.setParameters(params);
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
// Calculating the width of the preview so it is proportional.
float widthFloat = (float) (deviceHeight) * 4 / 3;
int width = Math.round(widthFloat);
// Resizing the LinearLayout so we can make a proportional preview. This
// approach is not 100% perfect because on devices with a really small
// screen the the image will still be distorted - there is place for
// improvment.
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, deviceHeight);
preview.setLayoutParams(layoutParams);
// Adding the camera preview after the FrameLayout and before the button
// as a separated element.
preview.addView(mPreview, 0);
}
您可能会看到complete
CameraActivity 类代码here
这是我的 CameraPreview
类:
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mHolder.setFixedSize(100, 100);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, now tell the camera where to draw the
// preview.
try {
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
} catch (IOException e) {
Log.d("DG_DEBUG", "Error setting camera preview: " + e.getMessage());
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null) {
// preview surface does not exist
return;
}
// stop preview before making changes
try {
mCamera.stopPreview();
} catch (Exception e) {
// ignore: tried to stop a non-existent preview
}
// make any resize, rotate or reformatting changes here
// start preview with new settings
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.setDisplayOrientation(90); // Portrait only
mCamera.startPreview();
} catch (Exception e) {
Log.d("DG_DEBUG", "Error starting camera preview: " + e.getMessage());
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// empty. Take care of releasing the Camera preview in your activity.
}
}
最佳答案
问题是由以下原因引起的:
params.setPictureSize(1200, 900);
因为相机不支持所需的尺寸。
使用 getSupportedPictureSizes
获取所有可用的预览尺寸。
检查相机可用的最大图片尺寸:
List<Size> allSizes = param.getSupportedPictureSizes();
Camera.Size size = allSizes.get(0); // get top size
for (int i = 0; i < allSizes.size(); i++) {
if (allSizes.get(i).width > size.width)
size = allSizes.get(i);
}
//set max Picture Size
params.setPictureSize(size.width, size.height);
关于java - 相机 java.lang.RuntimeException : setParameters failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33579918/
我正在将 NHibernate 3 引入 ASP.NET MVC 网络应用程序的数据访问层。 在 SQL Server 2008 R2 数据库中,geography 数据类型用于将纬度/经度坐标存储在
我想播放有效果的声音。 例如,我使用的是低通和高通,我想用鼠标位置(x,y)设置两个效果的参数。 我使用了DSP.reset()和DSP.setParameter(),但是有一个问题。 如果我越来越快
我有以下代码: String searchText = "..."; String sqlQuery = "FROM Studio s " + "WHERE fts('
这可能是我对JSP和JSTL的误解和资料不全造成的。我有一个网页,其中有输入元素,例如 当我尝试保存表单时,我会检查该 elementID 和其他元素是否符合某些约束“数字,小于 XXX”。如果他们
我正在尝试为我的 MongoDB 安装设置 logLevel 参数的自定义值。执行此操作的标准方法似乎是将 --setParameter 参数传递给 mongod.exe 可执行文件。 但我读了Con
在下面的代码片段中,取自 Blazor 示例,StartDate 属性在派生的 SetParameters 方法中初始化,而它可以这样初始化: [Parameter] DateTime StartDa
当我似乎在查询中使用参数时,出现错误 Invalid parameter number: number of bound variables does not match number of toke
作为构建配置的第一步,我尝试动态更改参数并在后续步骤中使用它。网上看的,好像这个方法是调用##teamcity[setParameter .但这似乎不起作用。它甚至不会在同一步骤中更改值。 例如,我创
我们正在尝试在我们的构建部署系统中集成“一次构建,随处部署”的模型。 MSDeploy 为此创造了奇迹,通过 CRC 校验和比较显着缩短了构建时间,并且( 大部分是 )它在使用参数化更改应用程序 we
我所做的事情必须与此处询问和回答的不同,因为该解决方案似乎不适合我:TeamCity, passing an id generated in one build step to a later bui
我在从正在 XLS 文件中添加参数的 Java 项目打印 PDF 文件时遇到问题。该项目读取 XML 文件,然后从 XSL 样式表生成 PDF 文件。文件内容见下文。 正如您在XLS文件中看到的,我想
如您所见,我有两个命名参数,一个由 setParameterList() 设置,一个由 setParmeter() 设置。问题是列表没有排序。当我显式设置订单字段时,它工作正常,但相同的字符串被传递到
我使用的是 Java 1.7 和 Hibernate 4.1.9。我对 Hibernate 比较陌生,所以如果我遗漏了任何关键信息,请告诉我。我有一个javax.persistence.Entity在
我正在尝试使用 hibernate 准备好的语句创建新表。看起来 "setparameter("values", value)" 添加了额外的引号来查询。我的代码: String hql = "cre
大家好我正在使用以下代码从我的应用程序访问相机:- public void onCreate(Bundle savedInstanceState) { super.onCreate(saved
我有一个 HQL 查询: select date_trunc('day', s.date), sum(s.price) from Sale as s group by date_trunc('
我有一个看起来像 tihs 的简单查询构建器: $qb2 = $this->createQueryBuilder('d') ->select('a.name, c.extern
我正在做一个简单的演示,我可以在我的 Activity 中将相机预览提供给 SurfaceView。我开始知道如果您不设置受支持的大小,setParameters() 会失败。但即使我这样做了,我也会
我最近为我的项目升级了 Jasper Reports 库,从 3.7.6 升级到 6.0.0。我终于可以构建 Maven 并且报告工作得很好。但是,setParameter() 函数似乎在不同版本之间
经过多次尝试,我想我终于把文档背熟了。然后,我需要你的帮助..我不明白为什么 Doctrine 向我显示这个错误: Invalid parameter number: number of bound
我是一名优秀的程序员,十分优秀!