'Cannot resolve method getOutputmediafile()
I want to make an application that takes picture it show the camera perfectly but i want to add the functionality of taking picture and storing it internaly in mobile this getOutMediafile() keeps popping up ?
package com.wordpress.bytedebugger.simplecamera;
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.Toast;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import static android.content.ContentValues.TAG;
import static android.provider.MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE;
import static android.widget.Toast.LENGTH_LONG;
public class MainActivity extends Activity {
private Camera mCamera = null;
private CameraView mCameraView = null;
private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null){
Toast.makeText(MainActivity.this,"Error creating media file, check storage permissions: ",Toast.LENGTH_LONG).show();
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try
{
mCamera = Camera.open();//you can use open(int) to use different cameras
} catch (Exception e){
Toast.makeText(MainActivity.this,"Failed to getCamera",Toast.LENGTH_LONG).show();
//Log.d("ERROR", "Failed to get camera: " + e.getMessage());
}
if(mCamera != null)
{
mCameraView = new CameraView(this, mCamera);//create a SurfaceView to show camera data
FrameLayout camera_view = (FrameLayout)findViewById(R.id.camera_view);
camera_view.addView(mCameraView);//add the SurfaceView to the layout
}
//button for taking picture
ImageButton imgtaken =(ImageButton) findViewById(R.id.imgtaken);
imgtaken.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// get an image from the camera
mCamera.takePicture(null, null, mPicture);
}
}
);
//btn to close the application
ImageButton imgClose = (ImageButton)findViewById(R.id.imgClose);
imgClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
System.exit(0);
}
});
}
}
Solution 1:[1]
You did not copy all necessary code from the Camera API guide. The method you ask about is shown tn the example here. Note that the tutorials do not perform full error checking required necessary production-grade code.
Solution 2:[2]
If you arrived here following the official android documentation camera example scroll down further into the documentation the method is written at the last as it's common to both video and the image capture
http://developer.android.com/guide/topics/media/camera.html#saving-media
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex Cohn |
| Solution 2 | Ahmad Malik |
