When I capture a photo from camera, I want to show it instead of live view.
Is there anything wrong with the URI or should I write a return page code?
What I am doing so far:
public void btnTakePhotoClicked(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String fullPath = "";
File imageFile = null;
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String pictureName = "IMG_" + timeStamp + ".jpg";
fullPath = Environment.getExternalStorageDirectory() + "/ImageFolder/" + pictureName;
File dir = new File(Environment.getExternalStorageDirectory() + "/ImageFolder/");
imageFile = new File(fullPath);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
Related
I am facing an issue now.
Why Bitmap.decodeFile() method is returning null?
I tried with the following advice.
but the above advice doesn't help me.
For directories reference
Code:
private File createPhotoFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
String imageFileName = "IMG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".png", storageDir);
String mCurrentPhotoPath = image.toString();
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,bmOptions);
//bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
Bitmap markedImage = waterMark(bitmap, "your_string", Color.RED, 90, 90, true);
File file = new File("path");
OutputStream os = new BufferedOutputStream(new FileOutputStream(String.valueOf(markedImage)));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.close();
return file;
}
Try adding bmOptions.inMutable = true after you have created it or try this
answer.
I have this Code to store a Picture:
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"fname_" + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
it stores the Picture in
/file:/storage/emulated/0/fname_.jpg
Then I would like to Show the Picture in imageView
Log.d("URI",imageUri.toString());
File imgFile = new File(imageUri.toString());
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
But It says:
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /file:/storage/emulated/0/fname_.jpg (No such file or directory)
I can See the Picture in Interer Speicher/fname_.jpg
Can soebody tell me the real path?
I suspect that imageUri.toString() does not return the path of your file in the SD Card,
You could try to change your Code like this :
File imageFile = new
File(Environment.getExternalStorageDirectory(),"fname_"
+ ".jpg");
mSavedPath = imageFile.getAbsolutePath();
imageUri = Uri.fromFile(imageFile);
intent.putExtra(
android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent,
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Then later :
File imgFile = new File(mSavedPath);
....
I have tried sharing the image to facebook, whatsapp, yahoo but none of them were able to load the image / attach image.
I have the following code :
File pictureFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_" + timeStamp + ".jpg");
FileOutputStream fos = new FileOutputStream(pictureFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
Intent imageIntent = new Intent(
imageIntent.setAction(Intent.ACTION_SEND);
imageIntent.setType("image/*");
imageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pictureFile));
PendingIntent shareIntent = PendingIntent.getActivity(this, 0, imageIntent, 0);
I have tried using Uri.parse(pictureFile.getAbsolutePath()) and Uri.parse(pictureFile.getParent()) and also tried putting the bitmap instead, but none of these works. Please help me
You need to use FileProvider to generate the Uri for file -
FileProvider.getUriForFile(context, packageName + ".fileprovider", file)
I am clicking images from android using camera intent.It opens the native camera app of android phone.I call onActivityResult to get the data from camera app.When i try to click more than 10 images continuously then on click of 'ok' button in camera it's not navigating me back to my app but on cancel it does.please tell me how can i get the solution?
Code
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
imagesFolder = new File(Environment.getExternalStorageDirectory(),
"DW");
imagesFolder.mkdirs();
// Create new folder
String timeStamp = new SimpleDateFormat("MM/dd/yyyy_hhmmssa")
.format(new Date());
// if (component_id != comp_id) { image_paths.clear(); }
component_id = comp_id;
String alter_timeStamp = timeStamp.replaceAll("/", "_");
cam_client_id = client_id;
cam_sub_client_id = sub_client_id;
fname = comp_name + "_" + component_id + "_" + alter_timeStamp
+ ".jpg";
fname = fname.replaceAll(",", "");
fname = fname.replaceAll("&", "");
fname = fname.replaceAll(" ", "_");
Log.i("SYNC", "fname is ->" + fname);
temp_image = image = new File(imagesFolder, fname);
// compress image size
temp_uri = uri = Uri.fromFile(image);
file_uri = uri.getPath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
context.startActivityForResult(intent, 90);
Thanks
I am trying to open an image I have stored on external memory. Here is the code I have:
File imagePath = new File(imageURI);
InputStream inputStream=null;
try {
inputStream = getContentResolver().openInputStream(Uri.parse(imageURI));
}catch(FileNotFoundException e){
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(inputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] originalImage = baos.toByteArray();
But it doesn't seem to be able to locate the file. The Uri is in the format content://com.android.providers.media.documents/document/image%3A21.
Thanks for any help.
In a project I am working on now I have external images in a directory on the SD card. I am using
String thePath = Environment.getExternalStorageDirectory() + "/myAppFiles”;
File imgFile = new File(thePath + " / " + "
externalImage.jpg ");
if (imgFile.exists()) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 6;
Bitmap bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
}
}
Try this:
File imagePath = new File(imageURI.getPath());
url.getPath() returns a String in the following format: "/mnt/sdcard/xxx.jpg", without the scheme type pre-fixed