如何在Vigo Video Hypstar等摄像机上实时预览录像机

时间:2018-04-11 06:07:27

标签: android ffmpeg opengl-es camera chromakey

我想用gif或图片Like Vigo

更改Surface预览底部叠加层

喜欢这个

enter image description here

请告诉我任何sdk或我使用的过滤器

我可以使用此

更改顶视图上的叠加层

Help of this

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

    }
  };

的输出

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:5)

使用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项目以获得更好的主意 和this project接近你想要做的事情。

答案 1 :(得分:2)

您需要使用外部库。

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

试试此库:

1)CameraFilter

2)This are Basic filters.

您可以在这里了解如何实施此基本过滤器。

3)EffectFactory

这就像Instagram一样。

3)FaceLandMarks

这就像Snapchat这样的效果,但为此你需要购买一个密钥才能在那个api页面中使用它。

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