Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为Android SurfaceView找到最佳像素格式_Android_Surfaceview - Fatal编程技术网

如何为Android SurfaceView找到最佳像素格式

如何为Android SurfaceView找到最佳像素格式,android,surfaceview,Android,Surfaceview,我发现在SurfaceView中更改像素格式对帧速率有很大影响。然而,我似乎找不到一种方法来选择每台设备的最佳格式 例如: @Override public void surfaceCreated(final SurfaceHolder holder) { //This line seems to fix speed issue with his res devices holder.setFormat(PixelFormat.RGBA_8888); androidGam

我发现在SurfaceView中更改像素格式对帧速率有很大影响。然而,我似乎找不到一种方法来选择每台设备的最佳格式

例如:

@Override
public void surfaceCreated(final SurfaceHolder holder) {
    //This line seems to fix speed issue with his res devices
    holder.setFormat(PixelFormat.RGBA_8888);
    androidGame.setSurfaceHolder(holder);
}
这使得我的游戏在Galaxy Nexus(ICS 4.0)上运行得更快,但在Motorola Xoom(3.2.1)上运行得较慢

如果我更改为PixelFormat.不透明,情况会相反。Nexus很慢,Xoom现在很快。因此,我需要能够确定每个设备的最佳格式。我尝试过使用getWindow().getAttributes().format,但它总是返回-1(不透明)。

Display。getPixelFormat()将获得显示的像素格式。我建议这样做

此方法不再受支持,将始终返回RGBA_8888

/**
 * Gets the pixel format of the display.
 * @return One of the constants defined in {@link android.graphics.PixelFormat}.
 *
 * @deprecated This method is no longer supported.
 * The result is always {@link PixelFormat#RGBA_8888}.
 */
@Deprecated
public int getPixelFormat() {
    return PixelFormat.RGBA_8888;
}

我可以在办公时间和谷歌IO 2012的Romain Guy交谈。不幸的是,没有合理的方法来检测要使用的最佳像素格式。您必须在每个设备上运行基准测试,以找到其最佳格式。

Display.getPixelFormat()在Galaxy Nexus上返回5,并且与PixelFormat的任何常量都不匹配。如果您的设备没有返回正确的值,则不确定如何帮助您。我想你可以在一个特定的案例中检测该设备,并使用最快的一个。@nmjohn根据这篇文章,返回的5实际上是BGRA_8888,看看这个建议是否真的有很好的性能会很有趣。