gpt4 book ai didi

android - 如何使相机预览透明?

转载 作者:搜寻专家 更新时间:2023-11-01 08:50:02 25 4
gpt4 key购买 nike

我看过很多关于摄像头预览的帖子,上面有透明图像/按钮,但我想知道如何制作半透明摄像头预览,我试图在 xml 文件中使用 #800000 使表面 View 透明,但它对相机预览没有影响。我正在尝试制作一个类似于透明屏幕的应用程序。这是我提供的一项服务:

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;
}

}`

最佳答案

您不能使相机预览透明。

但是你可以把它隐藏起来。只需将预览表面大小设置为 1x1 像素:

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

顺便说一句,这是最新的 Android 之一背后的技巧 Security holes .

吉拉德海莫夫

www.mobileedge.co.il

关于android - 如何使相机预览透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24408283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com