Camera中添加Camera的Zoom控件

发布于 2024-11-17 17:30:31 字数 300 浏览 0 评论 0原文

我正在制作一个相机应用程序,其中我使用 Surface View 作为相机和所有其他东西。我从以下链接中获取了指南。

http://www.brighthub.com/mobile/google-android/articles /43414.aspx

现在一切正常,但问题是我在相机中看不到任何缩放控件和亮度控件。如何设置请指导我。

提前致谢

I am making a Camera application in which i am using Surface View for camera and all other stuffs. I took the guidelines from the following link.

http://www.brighthub.com/mobile/google-android/articles/43414.aspx

Now everything works fine but the problem is that i cant see any Zoom Controls and Brightness Controls in the camera. How to set that please Guide me.

Thanks in advance

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

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

发布评论

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

评论(2

意中人 2024-11-24 17:30:31

在您的相机布局中添加 ZoomControls。

<ZoomControls
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/surface_camera"
android:layout_centerInParent="true"
android:id="@+id/CAMERA_ZOOM_CONTROLS">
</ZoomControls>

将这些变量添加到您的cameraActivity

int currentZoomLevel = 0, maxZoomLevel = 0;

然后将以下代码添加到您的surfaceChanged 方法中。

    ZoomControls zoomControls = (ZoomControls) findViewById(R.id.CAMERA_ZOOM_CONTROLS);

    if(params.isZoomSupported()){    
    maxZoomLevel = params.getMaxZoom();

    zoomControls.setIsZoomInEnabled(true);
        zoomControls.setIsZoomOutEnabled(true);

        zoomControls.setOnZoomInClickListener(new OnClickListener(){
            public void onClick(View v){
                    if(currentZoomLevel < MAX_ZOOM){
                        currentZoomLevel++;
                        camera.startSmoothZoom(currentZoomLevel);
                    }
            }
        });

    zoomControls.setOnZoomOutClickListener(new OnClickListener(){
            public void onClick(View v){
                    if(currentZoomLevel > 0){
                        currentZoomLevel--;
                        camera.startSmoothZoom(currentZoomLevel);
                    }
            }
        });    
   }
   else
     zoomControls.setVisibility(View.GONE);

In your camera layout add ZoomControls.

<ZoomControls
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/surface_camera"
android:layout_centerInParent="true"
android:id="@+id/CAMERA_ZOOM_CONTROLS">
</ZoomControls>

add these variables to your cameraActivity

int currentZoomLevel = 0, maxZoomLevel = 0;

Then add following code to your surfaceChanged method.

    ZoomControls zoomControls = (ZoomControls) findViewById(R.id.CAMERA_ZOOM_CONTROLS);

    if(params.isZoomSupported()){    
    maxZoomLevel = params.getMaxZoom();

    zoomControls.setIsZoomInEnabled(true);
        zoomControls.setIsZoomOutEnabled(true);

        zoomControls.setOnZoomInClickListener(new OnClickListener(){
            public void onClick(View v){
                    if(currentZoomLevel < MAX_ZOOM){
                        currentZoomLevel++;
                        camera.startSmoothZoom(currentZoomLevel);
                    }
            }
        });

    zoomControls.setOnZoomOutClickListener(new OnClickListener(){
            public void onClick(View v){
                    if(currentZoomLevel > 0){
                        currentZoomLevel--;
                        camera.startSmoothZoom(currentZoomLevel);
                    }
            }
        });    
   }
   else
     zoomControls.setVisibility(View.GONE);
苦行僧 2024-11-24 17:30:31

将这些变量添加到您的 Activity 类中

int currentZoomLevel = 0, maxZoomLevel = 0;
private Parameters params;
private Camera mCamera;
private LayoutInflater controlInflater = null;

添加到您的 onCreate 方法

controlInflater = LayoutInflater.from(getBaseContext());
    View viewControl = controlInflater.inflate(R.layout.custom, null);
    LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.MATCH_PARENT, 
                                                        LayoutParams.MATCH_PARENT);
    this.addContentView(viewControl, layoutParamsControl);

         ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomControls1);        

         if (params.isZoomSupported()) {
         final int maxZoomLevel = params.getMaxZoom();
         Log.i("max ZOOM ", "is " + maxZoomLevel);
         zoomControls.setIsZoomInEnabled(true);
         zoomControls.setIsZoomOutEnabled(true);

         zoomControls.setOnZoomInClickListener(new OnClickListener(){
         public void onClick(View v){
         if(currentZoomLevel < maxZoomLevel){
         currentZoomLevel++;
         //mCamera.startSmoothZoom(currentZoomLevel);
         params.setZoom(currentZoomLevel);
         mCamera.setParameters(params);
         }
         }
         });

         zoomControls.setOnZoomOutClickListener(new OnClickListener(){
         public void onClick(View v){
         if(currentZoomLevel > 0){
         currentZoomLevel--;
         params.setZoom(currentZoomLevel);
         mCamera.setParameters(params);
         }
         }
         }); 
         }
         else
         zoomControls.setVisibility(View.GONE);

中 将其添加到它自己的名为“custom.xml”的布局中

    <ZoomControls
    android:id="@+id/zoomControls1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="80dp"
    android:layout_marginTop="200dp" />

如果我以任何方式帮助您,请帮助我并查看我的 YouTube 频道,谢谢。
https://www.youtube.com/watch?v=MSdghmyCrOE

add these variables to your Activity Class

int currentZoomLevel = 0, maxZoomLevel = 0;
private Parameters params;
private Camera mCamera;
private LayoutInflater controlInflater = null;

add to your onCreate Method

controlInflater = LayoutInflater.from(getBaseContext());
    View viewControl = controlInflater.inflate(R.layout.custom, null);
    LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.MATCH_PARENT, 
                                                        LayoutParams.MATCH_PARENT);
    this.addContentView(viewControl, layoutParamsControl);

         ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomControls1);        

         if (params.isZoomSupported()) {
         final int maxZoomLevel = params.getMaxZoom();
         Log.i("max ZOOM ", "is " + maxZoomLevel);
         zoomControls.setIsZoomInEnabled(true);
         zoomControls.setIsZoomOutEnabled(true);

         zoomControls.setOnZoomInClickListener(new OnClickListener(){
         public void onClick(View v){
         if(currentZoomLevel < maxZoomLevel){
         currentZoomLevel++;
         //mCamera.startSmoothZoom(currentZoomLevel);
         params.setZoom(currentZoomLevel);
         mCamera.setParameters(params);
         }
         }
         });

         zoomControls.setOnZoomOutClickListener(new OnClickListener(){
         public void onClick(View v){
         if(currentZoomLevel > 0){
         currentZoomLevel--;
         params.setZoom(currentZoomLevel);
         mCamera.setParameters(params);
         }
         }
         }); 
         }
         else
         zoomControls.setVisibility(View.GONE);

add this in it's own layout called "custom.xml"

    <ZoomControls
    android:id="@+id/zoomControls1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="80dp"
    android:layout_marginTop="200dp" />

If I help you in any way help me out and check out my youtube channel THANKS.
https://www.youtube.com/watch?v=MSdghmyCrOE?

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