如何使相机preVIEW透明? [英] How to make a camera preview transparent?

查看:209
本文介绍了如何使相机preVIEW透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过很多职位有关摄像头preVIEW用透明图像/按钮上方,但我想知道如何使一个半透明相机preVIEW,我试图让surfaceview透明的# 800000在XML文件,但它拥有相机preVIEW没有效果..我试图做类似透明屏幕的应用程序。这里是我做了一个服务:

I've seen many post about camera preview with a transparent image/button ABOVE it, but I want to know how to make a semi transparent camera preview, I tried to make the surfaceview transparent with #800000 in the xml file, but it has no effect over the camera preview.. I'm trying to make an app similar to Transparent screen. Here is a service I made:

public class FlyingCamera extends Service implements SurfaceHolder.Callback{
    SurfaceView view;
    SurfaceHolder holder;
    Camera c;
    View child;
    LayoutInflater inflater;
    Context context;
    public Camera camera=null;


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();


    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
             PixelFormat.TRANSLUCENT);
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

    View myView = inflater.inflate(R.layout.camera_surface, null);
    view = (SurfaceView) myView.findViewById(R.id.surfaceView1);

    holder=view.getHolder();

    holder.addCallback(this);

    myView.setOnTouchListener(new OnTouchListener() {
           @Override
           public boolean onTouch(View v, MotionEvent event) {
               Log.d("Touch", "touch me");
           return false;
           }
         });
    // Add layout to window manager

    wm.addView(myView, params);

}





@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub

    return null;

}

@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    stopSelf();
    super.onDestroy();
    Log.d("Destroy","God Help DESTROY");
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera=Camera.open();

    try{
        camera.setPreviewDisplay(holder);
        camera.setDisplayOrientation(90);

    }catch(Exception e){
        Log.d("exceptie", "nu a mers");
    }
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub
    Camera.Parameters params=camera.getParameters();
    params.setPreviewSize(width, height);
    camera.setParameters(params);
    camera.startPreview();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera.stopPreview();
    camera=null;
}

}
`

推荐答案

您不能使摄像机preVIEW透明。

You cannot make the camera preview transparent.

但你可以把它隐藏起来。就在preVIEW表面大小设置为1x1像素的:

But you can make it hidden. Just set the preview surface size to 1x1 pixels:

   Camera.Parameters params = camera.getParameters();
   surfaceView.getLayoutParams().width = 1;
   surfaceView.getLayoutParams().height = 1;

这,顺便说一句,后面是最新的Andr​​oid的安全漏洞的。

This, BTW, is the trick behind one of the latest Android Security holes.

吉拉德Haimov

www.mobileedge.co.il

这篇关于如何使相机preVIEW透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆