0

I'm trying build a camera app in android using camera API.

I follow the instructions: https://examples.javacodegeeks.com/android/core/hardware/camera-hardware/android-camera-example/ and I have built one camera app

Now i need to display preview camera inside a frame and take picture include the frame

Please see the two pictures below:

Frame in resource folder : https://i.stack.imgur.com/AaNIQ.png

The photo I want to achieve: https://i.stack.imgur.com/UWXcq.jpg

Anyone can give me suggestions or if possible give me a simple example?

I searched about this but didn't get proper example.

Thank you so much.

Trung Đoan
  • 643
  • 7
  • 18
  • 1
    please clear your question ? – Shubham Sharma Dec 24 '17 at 16:02
  • I need to display preview camera inside a frame and take picture include the frame, you can see two image that was attached, please – Trung Đoan Dec 24 '17 at 16:10
  • A nice tutorial for a similar (even slightly more complicated task) had been [posted by Piotr Gurgul](https://dropbox.tech/machine-learning/augmented-camera-previews-for-the-dropbox-android-document-scanner) of DropBox few months earlier. – Alex Cohn May 15 '20 at 11:57

1 Answers1

0

Half of the answer can be found here: https://stackoverflow.com/a/47240902/192373.

As for keeping the same layout for full-res picture capture, first of all make sure that you keep preview- and picture- sizes in sync. This does not mean that they must be the same, but the aspect ratios should. Some devices have weird effects when the aspect ratio changes to capture a photo.

Next, you capture the jpeg as usual, unpack it to bitmap, overlay with the frame bitmap (you may need a hi-res version of your frame here) and combine the two (based on https://stackoverflow.com/a/4863551/192373):

public Bitmap combineImages(Bitmap picture, Bitmap frame) {
 Bitmap bmp = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888); 

 Canvas comboImage = new Canvas(bmp); 

 comboImage.drawBitmap(picture, 0f, 0f, null); 
 comboImage.drawBitmap(frame, 0f, 0f, null);  

 return bmp; 
} 
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I have tried your solution and it works well. Thank you so much – Trung Đoan Dec 26 '17 at 03:38
  • Hey Alex. Do you know they did this here https://www.youtube.com/watch?v=SKNPfO6qjk0 ? They managed to make the user take the picture in a specific frame...How did they do that ? – Kurt Miller Jan 15 '19 at 17:51
  • @KurtMiller this is not exactly how I interpret their video: *a)* they don't need the image to exactly match their frame, they simply choose an image that is aligned enough; *b)* they don't 'take picture', but store a preview image: it's good enough as evidence, they don't need it at very high quality. – Alex Cohn Jan 16 '19 at 17:02
  • @AlexCohn The problem with your interpretation is that you might have not considered that pictures will be sent to a central server where someone may actually look at them. So in that case preview won't be of much help... Anyways I was wondering if you could redirect le to some resources or tell me topics to google in order to study the technical aspect that can help me do something like that.... I'm reading this https://developer.android.com/guide/topics/media/camera right now – Kurt Miller Jan 16 '19 at 22:26
  • @KurtMiller preview resolution is usually more than enough to process a check. But same computer vision algorithm that the banking app uses could also trigger takePicture (or its camera2 analogue) as high-res JPEG. Note also that you linked a YouTube clip for iPhone, and it was probably carefully staged and redacted; so it would not be wise to expect exactly same from the app you are building. – Alex Cohn Jan 17 '19 at 10:47