Answer the question
In order to leave comments, you need to log in
How to get full photo from camera in android?
Good evening. All day I struggle with capturing a photo from the camera. Except how to get a miniature copy of the photo, nothing comes of it.
I follow these instructions:
developer.alexanderklimov.ru/android/photocamera.php
A file with an image from the camera camera is successfully created in this way:
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imgCamFile = new File(Environment.getExternalStorageDirectory(), "tempcamera.jpg");
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imgCamFile));
mCurrentPhotoPath = imgCamFile.getAbsolutePath();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
thumbnailBitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/tempcamera.jpg", options);
startActivityForResult(takePicture, 0);
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera"></uses-feature>
Answer the question
In order to leave comments, you need to log in
To get the image in full size, you need to first
force the camera to save the image in a temporary file:
private URI mImageUri;
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo;
try
{
// место где хранятся фото
photo = this.createTemporaryFile("picture", ".jpg");
photo.delete();
}
catch(Exception e)
{
Log.v(TAG, "Не получилось создать фото!");
Toast.makeText(activity, "Пожалуйста, проверьте Sd - карту", 10000);
return false;
}
mImageUri = Uri.fromFile(photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
//вызываем Intent камеры
activity.startActivityForResult(this, intent, MenuShootImage);
private File createTemporaryFile(String part, String ext) throws Exception
{
File tempDir= Environment.getExternalStorageDirectory();
tempDir=new File(tempDir.getAbsolutePath()+"/.temp/");
if(!tempDir.exists())
{
tempDir.mkdir();
}
return File.createTempFile(part, ext, tempDir);
}
imageUri
:public void grabImage(ImageView imageView)
{
this.getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
Bitmap bitmap;
try
{
bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
imageView.setImageBitmap(bitmap);
}
catch (Exception e)
{
Toast.makeText(this, "Ошибка загрузки", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Ошибка загрузки", e);
}
}
//вызов камеры после выполнения
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if(requestCode==MenuShootImage && resultCode==RESULT_OK)
{
ImageView imageView;
//делаем, что нужно с картинкой
this.grabImage(imageView);
}
super.onActivityResult(requestCode, resultCode, intent);
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application>
...
</application>
/ Storage Permissions
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
/**
* Checks if the app has permission to write to device storage
*
* If the app does not has permission then the user will be prompted to grant permissions
*
* @param activity
*/
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
}
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.M){
} else{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question