I need to capture Image and display it in another activity - android

I have an activity that starts the camera API.
I want to press the button (named by id "cptr_1") and take a picture and display it in another activity (PhotoPreview.class) where I can add photo effects.
I just need the code for:
ImageButton capture_1 = (ImageButton)findViewById(R.id.cptr_1);
capture_1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
And then how to transfer that image to PhotoPreview.class

You can take photo with the camera app of the device.
So when you click:
static final int ImageValue= 1;
ImageButton capture_1 = (ImageButton)findViewById(R.id.cptr_1);
capture_1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent takepic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takepic.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takepic, ImageValue);
}
}
});
Once capture is completed get the image back from the camera application
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ImageValue && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
}
}
Then send Bitmap to another activity.
Inside the activity that starts the camera API write:
Intent intent = new Intent(this, PhotoPreview.class);
intent.putExtra("GetBitmap", bitmap);
Inside PhotoPreview.class write:
Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("GetBitmap");
Also you may need to add those permissions to Android Manifest
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

either you can use an Intent to take picture or use a custom camera class
for camera intent for custom camera class
if u already have a custom camera class, you can use this code`Camera cam = Camera.open(cameraId);
capture_1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
cam.takePicture(null, null, mPicture);
} catch (Exception e) {
}
}
});
private PictureCallback mPicture = new PictureCallback() {
public void onPictureTaken(final byte[] data, Camera camera) {
try {
File mediaFile = new File("file path/filename.jpg");
FileOutputStream fos = new FileOutputStream(mediaFile);
fos.write(data);
fos.close();
cam.startPreview();
} catch (Exception e) {
}
}
};`

Related

Save/Read Bitmap in internal storage doesn't work

I tried to code a simple functionallity that would crop an image (stored in the drawable folder) after pressing a button, and return the cropped image in the first Activity in an imageView.
Aftrer trying to pass the bitmap in a arraybyte through an intent that didn't work, I am now trying to save the cropped image into the internal storage and read it in the OnActivityResult function, however when I am done cropping I get nothing in my ImageView.
For the cropping I used the following library : https://github.com/ArthurHub/Android-Image-Cropper/wiki
Here is the code:
public class MainActivity extends AppCompatActivity {
Button b;
ImageView preview;
final int REQUEST_CODE_TEST = 63;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.chooser);
preview = (ImageView) findViewById(R.id.preview);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Cropper.class);
startActivityForResult(intent, REQUEST_CODE_TEST);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_TEST && resultCode == RESULT_OK) {
try {
String path=data.getData().toString();
File f=new File(path,"profile.jpg");
Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(f));
preview.setImageBitmap(bitmap);
}catch (Exception e){
e.printStackTrace();
}
}
}
The crop actvity :
public class Cropper extends Activity {
CropImageView cropImageView;
Bitmap bitmap;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cropper);
bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.ic_bonnasse);
cropImageView=(CropImageView)findViewById(R.id.cropImageView);
cropImageView.setCropShape(CropImageView.CropShape.RECTANGLE);
cropImageView.setImageBitmap(bitmap);
button=(Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
#Override
public void finish() {
super.finish();
Intent retour=new Intent();
Bitmap crop=cropImageView.getCroppedImage();
Bitmap out=Bitmap.createScaledBitmap(crop, 200, 200, true);
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("Profile_pic", Context.MODE_PRIVATE);
File mypath=new File(directory,"profile.jpg");
FileOutputStream outputStream=null;
try{
outputStream=new FileOutputStream(mypath);
out.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.close();
}catch (Exception e){
e.printStackTrace();
}
retour.putExtra("directory",directory.getAbsolutePath());
}
Thanks for your help.
when you are finishing your crop activity , you are suppose to set your result status for your parent activity , otherwise the parent activity can not detect the result code .
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_TEST && resultCode == RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getParcelableExtra("bitmap");
preview.setImageBitmap(bitmap);
}
In this figure the result code is always RESULT_CANCEL , therefore your If block does not run.
Solution :
Do not override finish() method , just use it and change your listener with this in crop activity .
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent retour=new Intent();
Bitmap crop = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
Bitmap out=Bitmap.createScaledBitmap(crop, 200, 200, true);
retour.putExtra("bitmap", out);
setResult(RESULT_OK, retour);
finish();
}
});
In this case I just passed the bitmap into main activity , but if you are willing to save the bitmap then send it to main activity , you are suppose to save it and put it into retour.putExtra("directory",directory.getAbsolutePath());
in your crop activity , then get it by String directory = data.getStringExtra("directory"); in onActivityResult .
Although in my view the first way is better , you have a second one.

bitmap bad quality after set to imageview

I am creating a app that opens camera for user and after image captured it will be shows on ImageView! But the image in ImageView has very bad quality
here is the code:
public class Camera extends AppCompatActivity implements View.OnClickListener {
ImageView imgView;
Button camera, setBackground;
Intent i;
int cameraData = 0;
Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
initialize();
}
private void initialize() {
imgView = (ImageView) findViewById(R.id.bPicture);
camera = (Button) findViewById(R.id.bOpenCamera);
setBackground = (Button) findViewById(R.id.bSetBackground);
camera.setOnClickListener(this);
setBackground.setOnClickListener(this);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bitmap = (Bitmap) extras.get("data");
Bitmap resizedBmp = Bitmap.createScaledBitmap(bitmap, imgView.getWidth(),imgView.getHeight(), false);
imgView.setImageBitmap(resizedBmp);
}
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.bOpenCamera:
i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
case R.id.bSetBackground:
try {
WallpaperManager wallmngr = WallpaperManager.getInstance(this);
wallmngr.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
what should I do to increase image quality?
Use something other than the thumbnail. Quoting the documentation for ACTION_IMAGE_CAPTURE, with emphasis added:
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.
So, specify a Uri in EXTRA_OUTPUT where a full camera image should be written to. Then, use an image-loading library, like Picasso, to load the photo into your ImageView.
Here is a sample app that demonstrates using EXTRA_OUTPUT.
This is how I made it work for me! Assuming you are capturing an image, and would like to show the captured image in a new Activity, you can follow this way:
First on the click of button you can:
public void cameraFuture(View view) // <-- onClick() method of Camera Button
{
Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"MyPhoto.jpg");
outPutfileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outPutfileUri);
startActivityForResult(intent, TAKE_PIC);
}
Then on the onActivityResult() method, you can do this way:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PIC && resultCode==RESULT_OK){
Toast.makeText(this, outPutfileUri.toString(),Toast.LENGTH_LONG).show();
Intent bitIntent = new Intent(this, CameraTake.class);
bitIntent.putExtra("imageUri", outPutfileUri);
startActivity(bitIntent);
finish();
}
}
And in the next Activity, you can receive the file this way:
Intent receiveIntent = getIntent();
uri = receiveIntent.getParcelableExtra("imageUri");
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
receiveImg= null;
} else {
receiveImg= extras.getString("PASSER");
}
} else {
receiveImg= (String) savedInstanceState.getSerializable("PASSER");
}
File imgFile = new File(Environment.getExternalStorageDirectory(),"MyPhoto.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.camOut);
myImage.setImageBitmap(myBitmap);
}

Take picture and display in other activity with API Demo

I've been following the Camera API Demo from the android developer site. After fixing alot of stuf i've come to my last problem. I want to use the picture i've just taken and display it in another activity (like when after you take a picture you first gotta accept it or redo it style).
My TakePhoto class :
public class TakePhoto extends Activity {
public static final int MEDIA_TYPE_IMAGE = 1;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
ImageButton captureButton;
private Camera mCamera;
private CameraPreview mPreview;
private Handler handler = new Handler();
private int SELECT_PICTURE = 1;
private String selectedImagePath;
FrameLayout preview;
private String documentType;
private Camera.Parameters p;
private PictureCallback mPicture = new PictureCallback() {
private String TAG = "DocsPro";
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null) {
Log.d(TAG, "Error creating media file, check storage permissions : PICTURE FILE IS NULL");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
Log.d(TAG, "fos.new");
fos.write(data);
Log.d(TAG, "fos.write");
fos.close();
Log.d(TAG, "fos.close");
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
};
//Accessing cameras
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.scan);
Intent myIntent = getIntent();
documentType = myIntent.getStringExtra("documentType");
Button terug = (Button) findViewById(R.id.button_terug);
ImageButton iTerug = (ImageButton) findViewById(R.id.imageButton_terug);
ImageButton gallery = (ImageButton) findViewById(R.id.button_galery);
ImageButton flash = (ImageButton) findViewById(R.id.button_flash);
preview = (FrameLayout) findViewById(R.id.camera_preview);
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(TakePhoto.this, mCamera);
captureButton = (ImageButton) findViewById(R.id.button_capture);
preview.addView(mPreview);
captureButton.bringToFront();
gallery.bringToFront();
flash.bringToFront();
p = mCamera.getParameters();
gallery.setOnClickListener(
new OnClickListener(){
#Override
public void onClick(View v)
{
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
}
);
flash.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_ON){
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(p);
mCamera.startPreview();
Log.e("Torch","MODE ON");
}else if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_OFF){
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(p);
mCamera.release();
mCamera=null;
Log.e("Torch","MODE OFF");
}else if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_AUTO){
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(p);
mCamera.startPreview();
Log.e("Torch","MODE AUTO");
}else if(p.getFlashMode() == android.hardware.Camera.Parameters.FLASH_MODE_TORCH){
p.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
mCamera.setParameters(p);
mCamera.startPreview();
Log.e("Torch","MODE TORCH");
}else{
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(p);
mCamera.startPreview();
Log.e("Torch","MODE ELSE");
}
}
});
// Add a listener to the Capture button
captureButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
// get an image from the camera
handler.postDelayed(new Runnable() {
#Override
public void run() {
mCamera.autoFocus(autoFocusCallback);
}
}, 1500L);
}
AutoFocusCallback autoFocusCallback=new AutoFocusCallback() {
#Override
public void onAutoFocus(boolean success, Camera camera) {
mCamera.takePicture(null, null, mPicture);
}
};
});
// Add listeners to Terug buttons
terug.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(TakePhoto.this, PickDocumentType.class);
startActivity(intent);
finish();
}
});
// Add listeners to Terug buttons
iTerug.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(TakePhoto.this, PickDocumentType.class);
startActivity(intent);
finish();
}
});
}
/**
* A safe way to get an instance of the Camera object.
*/
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
}
/**
* Create a File for saving an image or video
*/
#SuppressLint("SimpleDateFormat")
private static File getOutputMediaFile(int type) {
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "DocsPro");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_" + timeStamp + ".jpg");
} else {
return null;
}
return mediaFile;
}
/**
* helper to retrieve the path of an image URI
*/
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if(cursor!=null)
{
//HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
//THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
else return null;
}
#Override
protected void onPause() {
super.onPause();
releaseCamera(); // release the camera immediately on pause event
}
private void releaseCamera() {
if (mCamera != null) {
mCamera.stopPreview();
mCamera.setPreviewCallback(null);
mCamera.release(); // release the camera for other applications
mCamera = null;
}
}
#Override
public void onStop()
{
super.onStop();
releaseCamera();
}
//Receiving camera intent result.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Log.d("foto", "Image saved to:\n" +
data.getData());
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
else if (requestCode == SELECT_PICTURE)
{
if (resultCode == RESULT_OK) {
releaseCamera();
Uri selectedImageUri = data.getData();
//MEDIA GALLERY
selectedImagePath = getPath(selectedImageUri);
Intent edit = new Intent(TakePhoto.this, EditPhoto.class);
edit.putExtra("filepath", selectedImagePath);
edit.putExtra("documentType", documentType);
startActivity(edit);
finish();
releaseCamera();
}
}
}
}
How do i get the image taken in the above class and transfer it to my new activity?
EDIT SOLUTION OF MY OWN :
I remembered that i had a method that would create the directory for my image, so i knew the location. Only trick was to get the filepath. And because the method getOutputMediaFile was saved in a File I just had to getAbsolutePath() and sent it with the intent :
String filepath = pictureFile.getAbsolutePath();
Intent edit = new Intent(TakePhoto.this, EditPhoto.class);
edit.putExtra("filepath", filepath);
startActivity(edit);
finish();
Then in the other activity i just get it like this and display it:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.bijsnijden);
Intent myIntent = getIntent();
imagePath = myIntent.getStringExtra("filepath");
documentType = myIntent.getStringExtra("documentType");
ImageView imageView = (ImageView) findViewById(R.id.Image);
imageView.setImageBitmap(BitmapFactory.decodeFile(imagePath));
}
Convert it to a Byte array before you add it to the intent, send it out, and decode.
//Convert to byte array
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Intent in1 = new Intent(this, Activity2.class);
in1.putExtra("image",byteArray);
Then in Activity 2:
byte[] byteArray = getIntent().getByteArrayExtra("image");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

Is there anything wrong with the code of saving camera image to file?

I thought it was simple to capture camera image to a file, since there are many examples. But after tying a lot of them, I still not get it work.
My code is:
public class MyActivity extends Activity {
private Button btn;
private ImageView imageView;
private static final File photoPath = new File(Environment.getExternalStorageState(), "camera.jpg");
private static final int CAMERA = 1;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
setListeners();
}
private void setListeners() {
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoPath));
startActivityForResult(intent, CAMERA);
}
});
}
private void findViews() {
btn = (Button) findViewById(R.id.btn);
imageView = (ImageView) findViewById(R.id.imageView);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA) {
if (resultCode == RESULT_OK) {
try {
Bitmap bitmap = getCameraBitmap(data);
if (bitmap == null) {
Toast.makeText(MyActivity.this, "Can't get bitmap from camera", Toast.LENGTH_LONG).show();
} else {
imageView.setImageBitmap(bitmap);
}
} catch (IOException e) {
Toast.makeText(MyActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
}
}
public Bitmap getCameraBitmap(Intent data) throws IOException {
if (data == null) {
// try solution 1
try {
return MediaStore.Images.Media.getBitmap(getContentResolver(), Uri.fromFile(photoPath));
} catch (FileNotFoundException e) {
return BitmapFactory.decodeFile(photoPath.getAbsolutePath());
}
} else {
Uri image = data.getData();
if (image != null) {
// try solution 3
InputStream inputStream = getContentResolver().openInputStream(image);
return BitmapFactory.decodeStream(inputStream);
} else {
// try solution 4
return (Bitmap) data.getExtras().get("data");
}
}
}
}
But it still get "Can't get bitmap from camera" shown. I don't known where is wrong.
I also created a working demo: https://github.com/freewind/AndroidCameraTest, you can see the full code there, and you may clone it and have a try on your own android device :)
Update
This code is working fine on android emulators, but not on my android pad.
I have seen this problem too; I removed intent.putExtra(MediaStore.EXTRA_OUTPUT,...), and it worked using the method:
stream = getContentResolver().openInputStream(data.getData());
image = BitmapFactory.decodeStream(stream);

How can I store the imagePath of the image that I took using the camera activity into the database and retrieving the path?

how to store the imagePath of the image that I had captured using the camera activity to database. I also need to retrieve that imagePath and display on another activity?
Can someone help me please?
Update:
public class Image_secondPage extends Activity
{
public static final int CAMERA_RESULT = 1;
Button btn1;
ImageView imageView1;
private final String tag = getClass().getName();
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.image_secondpage);
imageView1 = (ImageView)findViewById(R.id.imageView1);
Button btnNext = (Button)findViewById(R.id.buttonNext);
btnNext.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(Image_secondPage.this, ImagesPage.class);
startActivity(intent);
}
});
PackageManager pm = getPackageManager();
if(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA))
{
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI);
startActivityForResult(i, CAMERA_RESULT);
}
else
{
Toast.makeText(getBaseContext(), "Camera is not available", Toast.LENGTH_LONG).show();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Log.i(tag, "Receive the camera result");
if(resultCode == RESULT_OK && requestCode == CAMERA_RESULT)
{
File out = new File(getFilesDir(), "newImage.jpg");
if(!out.exists())
{
Toast.makeText(getBaseContext(), "Error while capturing image", Toast.LENGTH_LONG).show();
return;
}
Bitmap mBitmap = BitmapFactory.decodeFile(out.getAbsolutePath());
imageView1.setImageBitmap(mBitmap);
}
}
#Override
protected void onDestroy()
{
super.onDestroy();
imageView1 = null;
}
I am supposed to get the imagePath that I have captured and show the image on the imageView that I had on the next class but I don't know how. Can someone help me?
try use this
bitmap = (Bitmap) data.getExtras().get("data");
this will give you bitmap image, then you can save it to database or anything you want.
let me know if this not solve your problem.

Categories

Resources