15

我想用 gif 或图像更改 Surface 预览底部叠加层,例如Vigo

像这样

在此处输入图像描述

请告诉我任何 sdk 或我用于此过滤器的内容

我可以使用此更改顶视图上的叠加层

这个的帮助

 PictureCallback cameraPictureCallbackJpeg = new PictureCallback() 
  {  
    @Override
    public void onPictureTaken(byte[] data, Camera camera) 
    {
      // TODO Auto-generated method stub   
      Bitmap cameraBitmap = BitmapFactory.decodeByteArray
                                                                  (data, 0, data.length);

   int   wid = cameraBitmap.getWidth();
     int  hgt = cameraBitmap.getHeight();

    //  Toast.makeText(getApplicationContext(), wid+""+hgt, Toast.LENGTH_SHORT).show();
      Bitmap newImage = Bitmap.createBitmap
                                        (wid, hgt, Bitmap.Config.ARGB_8888);

      Canvas canvas = new Canvas(newImage);

      canvas.drawBitmap(cameraBitmap, 0f, 0f, null);

     Drawable drawable = getResources().getDrawable
                                                          (R.drawable.mark3);
      drawable.setBounds(20, 30, drawable.getIntrinsicWidth()+20, drawable.getIntrinsicHeight()+30);
    drawable.draw(canvas);



      File storagePath = new File(Environment.
                    getExternalStorageDirectory() + "/PhotoAR/"); 
      storagePath.mkdirs(); 

      File myImage = new File(storagePath,
                    Long.toString(System.currentTimeMillis()) + ".jpg");

      try
      {
        FileOutputStream out = new FileOutputStream(myImage);
        newImage.compress(Bitmap.CompressFormat.JPEG, 80, out);


        out.flush();
        out.close();
      }
      catch(FileNotFoundException e)
      {
        Log.d("In Saving File", e + "");    
      }
      catch(IOException e)
      {
        Log.d("In Saving File", e + "");
      }

      camera.startPreview();



      newImage.recycle();
      newImage = null;

      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_VIEW);

      intent.setDataAndType(Uri.parse("file://" + myImage.getAbsolutePath()), "image/*");
      startActivity(intent);

    }
  };

这个的输出

在此处输入图像描述

在此处输入图像描述

4

2 回答 2

6

使用GLSurfaceView。基本思想是在 GLSurfaceView 中进行相机预览并绘制 OpenGL 渲染。
常见的方法是继承 GLSurfaceView 并实现 GLSurfaceView.Renderer。渲染任务是通过实现接口来执行的。

public class CameraRenderer extends GLSurfaceView implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener { 
    @Override
    public synchronized void onSurfaceCreated(GL10 gl, EGLConfig config) {
        ...
        //compile shader here
    }

    @Override
    public synchronized void onSurfaceChanged(GL10 gl, int width, int height) {
        ...
        //open camera and start preview here
    }

    @Override
    public synchronized void onDrawFrame(GL10 gl) {
        ...
        //draw frame as required
    }

}

看看这个grafika项目以获得更好的想法,这个项目接近你想要做的事情。

于 2018-05-16T11:48:54.607 回答
2

您需要为此使用外部库。

用于在相机中使用滤镜以及此类虚拟效果。

试试这个库:

1)相机滤镜

2)这是基本过滤器。

您可以在此处了解如何实现此基本过滤器。

3)效果工厂

这是像 Instagram 一样的效果。

3) FaceLandMarks

这是 Snapchat 之类的效果,但为此您需要从该 api 页面购买使用该密钥的密钥。

我希望这会有所帮助,如果这不是您的答案,请忽略此答案。

于 2018-05-16T06:59:14.047 回答