Okay, so I have an onclick on a button that opens the camera, when I take a picture and save it how do I get the file name+location of where it was saved to open it in my app?
Here is my button click
Button btncamera = (Button)findViewById(R.id.btncamera);
btncamera.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent cameraIntent = nwe Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 2500);
}
}
Here is my Result it doesn't contain anything, but it will start another Intent to display the image:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
}
Maybe I am doing it wrong, but any guidance would be much appreciated thanks!
Try adding this to your onActivityResult.
Bitmap picture = (Bitmap) data.getExtras().get("data");
Take the image out of the camera intent, create a bitmap out of it, and then use it from there. Write it to a file, or import it directly into a display resource.
Also be sure to check your ResultCode to determine if a picture actually has been taken.
Related
I am working on a semester project and it requires that I send images from an android device to server without storing the image. I want to make sure my cameta application is working properly. I want to check this using an ImageView that displays the captured image on the screen. How can I do it? I thought I could load from drawable but I cannot add files to drawable during runtime.
Thanks for any support
You don't need to save it to the drawable. These are the two steps:
1.Convert the captured image to Bitmap
2.Set the bitmap image to an imageview
Ref: StackOverflow Answer
private void takePicture(){ //you can call this every 5 seconds using a timer or whenever you want
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap picture = (Bitmap) data.getExtras().get("data");//this is your bitmap image and now you can do whatever you want with this
imageView.setImageBitmap(picture); //for example I put bmp in an ImageView
}
}
This question already has answers here:
Low picture/image quality when capture from camera
(3 answers)
Closed 3 years ago.
I want the good quality image to show in ImageView and upload to the server. I have searched the Internet, StackOverflow and GitHub, but I could not find the answer, maybe somebody knows how can fix it?
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { //work android
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
imageReturnedIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//try
if (resultCode == RESULT_OK ) {// work every android than need click OK
//working
Uri selectedImage = imageReturnedIntent.getData();//convert to for bitmap that can send
Bundle extras = imageReturnedIntent.getExtras();//finish converting and copy the image
bitmap = extras.getParcelable("data");//receive image to bitmap
imageView.setImageBitmap(bitmap);
onCreate:
btnCamera.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, 0);
}
});
What is wrong here?
The Intent you send returns only low-quality picture as a small bitmap.
If you want the full-resolution image, you need to prepare the file where this image will be saved and provide all necessary information to the Camera application. The details are available at Save the full-size photo section, with all explanations and the code samples.
I have my app so I have the ability to open the camera and take a picture, the app then shows me a preview of the photo just taken, and when I press 'OK', it is gone. I want to be able to save the image I have taken to my internal storage on my phone, (and possibly have a function so I can access my gallery and preview it later on). I have searched everywhere but all the help I am getting is to store it on an SD card, whereas I want to use my phones built in storage. Thank you
My code so far:
Button butCamera;
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
butCamera = (Button) findViewById(R.id.butCamera);
imageView = (ImageView) findViewById(R.id.imageView);
butCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
What you are trying to achieve is quite complex,
an i'm not sure you could use this common storage method to achieve it
File root = Environment.getExternalStorageDirectory();
But have a loot at this post, it should have what you require
android - save image into gallery
To store the Image to Internal storage of the device, you will have to do something like this.
File file = new File(Environment.getExternalStorageDirectory(), "MyFile.jpg");
Uri uri = Uri.fromFile(file);
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_REQUEST);
I'm trying to do an app (with the master/detail flow template) that in the detail fragment, has an ImageView that shows an image taken by the camera.
For this option, I added a button to the ActionBar that opens a Dialog box and asks the user if he wishes to add an image with the camera. So for this option I made this two methods that are called when the user clicks ok. However, (here I now I'm making huge mistakes) I don't have the least idea about how to call the onActivityResult() with the end of having my ImageIcon showing the thumbnail retrieved from the camera. (as developer.android tutorial shows)
If anyone of you guys knows what I am doing wrong, I would be really happy to hear all the solutions that you can give me, since I wasn't able to find a solution to this problem anywhere.
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
onActivityResult(REQUEST_IMAGE_CAPTURE, RESULT_OK, takePictureIntent);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ImageView mImageView = (ImageView) findViewById(R.id.imageView1);
mImageView.setImageBitmap(imageBitmap);
}
}
THANKS A LOT!!!!
You do not have to call onActivityResult explicitly. onActivityResult method called in the parent activity when the immediately child/successor activity finished its task. So when your Image taking activity will finished the task it call automatically a "requestCode" and Image data(If your Image taking activity take a picture otherwise it will be null).
For more details about the onActivityResult see the here.
To set the thumbnail to the imageview you can do this in the following way.
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
You can see this tutorial about the how to take Image using intent.
Happy Coding
You have to create a scaled bitmap from the bitmap received in onActivityResult. You will get information about how to create a scaled bitmap Here
You can set the width and height as desired
imageBitmap = Bitmap.createScaledBitmap(realImageBitmap, final_width, final_height, false);
imageView.setImageBitmap(imageBitmap);
in my app i m calling built in camera for capturing picture but i want to set that picture into an image view following is the code . so what code should i add to it to set the picture into imageview.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == 0) {
String result = data.toURI();
// ...
}
}
Thanks in advance
Add a button and an ImageView to your main layout. When you click the button, first intent.putExtra to specify where the image will be stored, then start the camera intent. In your onActivityResult, if the resultCode comes back 0 that means the user accepted the picture. In this case, go grab the image from the path you specified as an extra of the intent. Create a bitmap from the file specified by the path, then set the image bitmap in your ImageView.