Galaxy 选项卡上的肖像相机方向

发布于 2024-10-31 15:36:08 字数 1102 浏览 4 评论 0原文

我正在三星 Galaxy Tab(7 英寸)上进行开发。我的应用程序必须仅处于纵向模式,即我已在我的应用程序和设备设置中将其锁定为纵向模式。问题是当我尝试旋转相机预览时,它当前以错误的方向旋转 90 度。

现在这是我的surfaceCreatedcamera.setDisplayOrientation

    public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    try {
        camera.setPreviewDisplay(holder);
        Camera.Parameters parameters = camera.getParameters();
        parameters.setPictureFormat(PixelFormat.JPEG);
        parameters.set("orientation", "portrait");
        //camera.setDisplayOrientation(90); 
        parameters.setRotation(90);
        camera.setParameters(parameters);
    }
    catch (IOException exception) {
        camera.release();
    }
}

(90)似乎不起作用(它什么也没做,这就是我将其注释掉的原因)。然而,parameters.setRotation(90) 实际上完成了工作!但它会在应用程序的一侧创建一个丑陋的“闪烁颜色”“条纹”。 setDisplayOrientation() 应该对我有用,因为我正在运行 android api 8 (Froyo 2.2)!

谷歌上有一个关于与旋转问题相关的问题http:// /code.google.com/p/android/issues/detail?id=1193#c26,但据我所知,它没有对我的问题提出任何建议。

与此问题相关的任何和所有解决方案将不胜感激!谢谢!

I am developing on/for a Samsung Galaxy Tab (7inches). My application has to be in portrait mode only, i.e i have locked it to portrait mode in my application and in the device settings. The problem is when i try to rotate the camera preview, it is currently rotated 90 degrees in the wrong direction.

Right now this is my surfaceCreated

    public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    try {
        camera.setPreviewDisplay(holder);
        Camera.Parameters parameters = camera.getParameters();
        parameters.setPictureFormat(PixelFormat.JPEG);
        parameters.set("orientation", "portrait");
        //camera.setDisplayOrientation(90); 
        parameters.setRotation(90);
        camera.setParameters(parameters);
    }
    catch (IOException exception) {
        camera.release();
    }
}

The camera.setDisplayOrientation(90) does not seem to be working (it does nothing, which is why i have commented it away). However the parameters.setRotation(90) DOES IN FACT GET THE JOB DONE! but it creates an ugly "stripe" of "flickering colors" along the side of the application. setDisplayOrientation() should work for me, since i am running android api 8 (Froyo 2.2)!!

There is a thread on google about problems pertaining to rotational issues http://code.google.com/p/android/issues/detail?id=1193#c26, but to the best of my knowledge it does not suggest anything for my problem.

Any and all solutions pertaining to this problem will be greatly appreciated! thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人问我粥可暖 2024-11-07 15:36:08

这在 Samsung Galaxy 选项卡中对我有用:

public void surfaceCreated(SurfaceHolder holder)
    {
    // The Surface has been created, acquire the camera and tell it where to draw.
    mCamera = Camera.open();

    Parameters params = mCamera.getParameters();

    if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
    {
    params.set("orientation", "portrait");
    mCamera.setDisplayOrientation(90);
    }

    try
    {
    mCamera.setPreviewDisplay(holder);
    }
    catch (IOException exception)
    {
    mCamera.release();
    mCamera = null;
    }

    }

This worked for me in Samsung Galaxy tab:

public void surfaceCreated(SurfaceHolder holder)
    {
    // The Surface has been created, acquire the camera and tell it where to draw.
    mCamera = Camera.open();

    Parameters params = mCamera.getParameters();

    if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
    {
    params.set("orientation", "portrait");
    mCamera.setDisplayOrientation(90);
    }

    try
    {
    mCamera.setPreviewDisplay(holder);
    }
    catch (IOException exception)
    {
    mCamera.release();
    mCamera = null;
    }

    }
魄砕の薆 2024-11-07 15:36:08

如果您的应用程序设计为仅拍摄肖像照片,那么最简单的方法就是在拍摄照片后旋转图像数据,而不必担心相机设置。我不确定选项卡是否有问题(我从未尝试过旋转相机预览),但拍摄后旋转图像非常简单......问题仅在于您需要知道哪个方向拍摄照片时正在握住设备。如果这不是您关心的问题,请不要担心:)

If your application is designed to only take Portrait photos, then the simplest thing to do is to just rotate the image data after you've taken the photo, and not worry about the camera settings. I'm not sure if the Tab is buggy (I've never tried to rotate the camera preview) but rotating the image after you've taken the shot is very simple... the problem is only if you need to know which way the device was being held when the picture was taken. If that's not a concern for you, then don't fret over it :)

苍暮颜 2024-11-07 15:36:08

试试这个。我编写了这段代码并在 Galaxy Tab 上进行了测试。代码运行良好

public void surfaceCreated(SurfaceHolder holder) {

    camera = Camera.open();

    try {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
        {                       
         camera.setDisplayOrientation(90);
        } else {
          Parameters parameters = camera.getParameters();
          parameters.setRotation(90);       
          camera.setParameters(parameters); 
        }

        camera.setPreviewDisplay(holder);
    } catch (IOException exception) {
        camera.release();
    }
}

try this. I make this code and test on Galaxy Tab. The code works well

public void surfaceCreated(SurfaceHolder holder) {

    camera = Camera.open();

    try {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
        {                       
         camera.setDisplayOrientation(90);
        } else {
          Parameters parameters = camera.getParameters();
          parameters.setRotation(90);       
          camera.setParameters(parameters); 
        }

        camera.setPreviewDisplay(holder);
    } catch (IOException exception) {
        camera.release();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文