E
Extremefall
Ambitioniertes Mitglied
- 3
Hallo,
ich habe eine App, die momentan ein Foto erzeugt, ohne dass ein Vorschaubild angezeigt wird. Leider klappt es nur, wenn die App den Fokus hat. Nun habe ich schon einige Funktionen, die auch funktionieren, wenn die App im Hintergrund läuft. Ich möchte also die App im Hintergrund laufen lassen und dann ein Foto machen.
Mein Code bisher:
Habe ich also die Möglichkeit, bei minimierter App ein Foto zu schießen?
ich habe eine App, die momentan ein Foto erzeugt, ohne dass ein Vorschaubild angezeigt wird. Leider klappt es nur, wenn die App den Fokus hat. Nun habe ich schon einige Funktionen, die auch funktionieren, wenn die App im Hintergrund läuft. Ich möchte also die App im Hintergrund laufen lassen und dann ein Foto machen.
Mein Code bisher:
PHP:
[LEFT]@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3)
{
mHandlerFoto.removeCallbacks(mUpdateTimeTaskFoto);
mHandlerFoto.postDelayed(mUpdateTimeTaskFoto, 10000);
[/LEFT]
}
[LEFT]@Override
public void surfaceCreated(SurfaceHolder holder)
{
// The Surface has been created, acquire the camera and tell it where
// to draw the preview.
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
//stop the preview
mCamera.stopPreview();
//release the camera
mCamera.release();
//unbind the camera from this object
mCamera = null; [/LEFT]
}
[LEFT]
private Runnable mUpdateTimeTaskFoto = new Runnable() {
public void run() {
//get camera parameters
parameters = mCamera.getParameters();
//set camera parameters
mCamera.setParameters(parameters);
mCamera.startPreview();
//sets what code should be executed after the picture is taken
Camera.PictureCallback mCall = new Camera.PictureCallback()
{
@Override
public void onPictureTaken(byte[] data, Camera camera)
{
//decode the data obtained by the camera into a Bitmap
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
//set the iv_image
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path, "FitnessGirl.jpg");
try {
fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
mCamera.takePicture(null, null, mCall);
}[/LEFT]
};