1

I'm implementing a custom camera, in the layout I have a rectangle inside the layout, where the user have to put his card, so after take the photo i need crop the picture, taking the reference the rectangle.

Any suggestion of how to do this?

enter image description here

Javier Olan
  • 560
  • 7
  • 14

1 Answers1

2

Possibly you can use a library that do this on your behalf. If you are not fully satisfied and need to understand how it works the process you can read the API. I do not know exact if you mean the selection have to be a rectangle of you are referring to the rectangle of your customer view where the card should fit, in the first case the library from Arthurhub should be enough

if you want to implement from scratch, I guess you need to use Matrix enter link description here

https://github.com/ArthurHub/Android-Image-Cropper

trocchietto
  • 2,607
  • 2
  • 23
  • 36
  • Thanks, at the end I used math for determinate the new size of the picture, I use a cross-multiplication to get the relative size. – Javier Olan Aug 21 '16 at 22:16
  • @JavierOlan can you please post the code how you have achieved this programmatically. I need the same thing to be done and its working for small devices but for high resolution devices its not working – Waqar UlHaq Oct 18 '18 at 08:02
  • Yes sure, here is the method https://gist.github.com/javikin/1de5fc5196abef9f52cdff4f40e4ed33, and here you can find the layout https://gist.github.com/javikin/ebf0dd43ee80f1be969d901ffe1bb302, I'm not sure if still works because is a 2 years implementation. – Javier Olan Oct 19 '18 at 15:00
  • 1
    nice @JavierOlan to be so helpful after few years – trocchietto Oct 19 '18 at 20:09
  • I tried your code @JavierOlan but could not get it to work when the preview of the camera is stretched. Do you think this can be solved using other math? Please notice: https://stackoverflow.com/questions/69480137/metadataoutputrectconvertedfromlayerrect-in-android – Robin Oct 07 '21 at 14:16