-1

I am working on a camera app.The camera preview show is with 4:3 ratio,When i take a photo i get the complete image or full screen image.

Since i am showing the user a Camera Preview with 4:3 ratio, i want the user to also get the image with 4:3 ratio only.

I have seen many libraries which gives the user an option to crop, but here as i give path of the image and then it should crop the image and display it to user.

How can i achieve this ?

user2056563
  • 600
  • 2
  • 12
  • 37
  • The best library I found to crop images was [Android-Image-Cropper](https://github.com/ArthurHub/Android-Image-Cropper). See this [answer](https://stackoverflow.com/a/51985041/8383332). – Soon Santos Aug 23 '18 at 11:48

2 Answers2

0

I don't think android has an out of the box cropper - but you can crop your own with Bitmap.createBitmap(originalBitmap, x1, y1, x2, y2)

Chris
  • 846
  • 6
  • 16
  • Chris,But what about the aspect ratio ? – user2056563 Apr 04 '16 at 08:00
  • 1
    You can ensure the new bitmap has the correct aspect ratio by calculating your coordinates correctly. You take the biggest 4:3 cutout of the bitmap. Caveat though - this isn't likely to be a great experience for users, so you should create some on-screen window that displays where you're going to cut out the new image so they can adjust it. – Chris Apr 04 '16 at 08:02
  • I agree with @Chris, you should let the user confirm the crop and/or change the area. I used [this useful library](http://mvnrepository.com/artifact/com.soundcloud.android/android-crop/0.9.10) to do it. – Ayoub Apr 04 '16 at 08:12
  • If you need some documentation you can look [here](https://github.com/jdamcd/android-crop) – Ayoub Apr 04 '16 at 08:14
  • @Ayoub thanks, i dont want the user to be given an option to select arear to crop, just want to crop the image and display or save – user2056563 Apr 04 '16 at 08:15
  • The problem with that, is that you'll inevitably cut off someone's head from the picture and they won't be pleased – Chris Apr 04 '16 at 18:57
0

Each Camera on each Android device has List of Preview Sizes and Picture Sizes.

Camera.Parameters parameters = camera.getParameters();
List<Size> preview_sizes = parameters.getSupportedPreviewSizes();
List<Size> pictures_sizes = parameters.getSupportedPictureSizes();

Try to loop all this Sizes and pick 4:3. So your result will be 4:3 without cropping.


Read more here.

Volodymyr Kulyk
  • 6,455
  • 3
  • 36
  • 63