Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void opnenCamera() {
- if (checker.lacksPermissions(PERMISSIONS_CAMERA_CAPTURE)) {
- startPermissionsActivity(PERMISSIONS_CAMERA_CAPTURE);
- } else {
- Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- // Ensure that there's a camera activity to handle the intent
- if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
- // Create the File where the photo should go
- File photoFile = null;
- try {
- photoFile = createImageFile();
- } catch (IOException ex) {
- // Error occurred while creating the File
- ex.printStackTrace();
- }
- // Continue only if the File was successfully created
- if (photoFile != null) {
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(MainActivity.this,
- BuildConfig.APPLICATION_ID + ".provider", destination));
- startActivityForResult(takePictureIntent, CAPTURE_IMAGE);
- }
- }
- }
- }
- private File createImageFile() throws IOException {
- // Create an image file name
- if (checker.lacksPermissions(PERMISSIONS_WRITE_EXTERNAL_STORAGE)) {
- startPermissionsActivity(PERMISSIONS_WRITE_EXTERNAL_STORAGE);
- } else {
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
- String imageFileName = timeStamp + "_";
- File storageDir =
- Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
- imageCamera = File.createTempFile(imageFileName, /* prefix */ //сам файл фото
- ".jpg", /* suffix */
- storageDir /* directory */);
- // Save a file: path for use with ACTION_VIEW intents
- mCurrentPhotoPath = imageCamera.getAbsolutePath();//путь до фото
- Log.d("Getpath", "Cool" + mCurrentPhotoPath);
- }
- return imageCamera;
- }
- if ((requestCode == CAPTURE_IMAGE) && (data != null)) {
- isCamFoto = true;
- // Get the dimensions of the View
- int targetW = imageViewUppload.getWidth();
- int targetH = imageViewUppload.getHeight();
- // Get the dimensions of the bitmap
- BitmapFactory.Options bmOptions = new BitmapFactory.Options();
- bmOptions.inJustDecodeBounds = true;
- BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
- int photoW = bmOptions.outWidth;
- int photoH = bmOptions.outHeight;
- // Determine how much to scale down the image
- int scaleFactor = Math.min(photoW / targetW, photoH / targetH);
- // Decode the image file into a Bitmap sized to fill the View
- bmOptions.inJustDecodeBounds = false;
- bmOptions.inSampleSize = scaleFactor;
- Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
- imageViewUppload.setImageBitmap(bitmap);
- Toast.makeText(MainActivity.this, "Фото сохранено и выбрано!", Toast.LENGTH_LONG)
- .show();
- } else {
- showError("Вы не выбрали файл");
- }
Add Comment
Please, Sign In to add comment