Created
September 26, 2017 01:44
-
-
Save Tom-Ski/62b2503c3211644103979d291eaaf30b to your computer and use it in GitHub Desktop.
Simple Libgdx + Android camera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mygdx.game; | |
import android.graphics.PixelFormat; | |
import android.hardware.Camera; | |
import android.os.Bundle; | |
import android.view.SurfaceView; | |
import android.view.View; | |
import android.widget.FrameLayout; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.backends.android.AndroidApplication; | |
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; | |
import com.badlogic.gdx.backends.android.AndroidGraphics; | |
public class AndroidLauncher extends AndroidApplication { | |
@Override | |
protected void onCreate (Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); | |
config.r = 8; | |
config.g = 8; | |
config.b = 8; | |
config.a = 8; | |
View view = initializeForView(new MyGdxGame(), config); | |
((SurfaceView)((AndroidGraphics)Gdx.graphics).getView()).getHolder().setFormat(PixelFormat.TRANSLUCENT); | |
CameraPreview preview = new CameraPreview(this, getCameraInstance()); | |
FrameLayout layout = new FrameLayout(this); | |
layout.addView(view); | |
layout.addView(preview); | |
setContentView(layout); | |
} | |
public static Camera getCameraInstance(){ | |
Camera c = null; | |
try { | |
c = Camera.open(); // attempt to get a Camera instance | |
} | |
catch (Exception e){ | |
// Camera is not available (in use or does not exist) | |
} | |
return c; // returns null if camera is unavailable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment