squared output photo similar to preview - android

I have used the Commonsware-cwac library exactly like the demo app. After resizing the framelayout which the preview is contained in I achieve a squared preview that maintains correct ratio and preview size. However, after I capture I would like to get a a photo with the same size as the preview. Now, when I capture a new photo, the saved photo is much bigger due to the fact that it captures the original and non-squared preview.
How can the output photo capture the same as the preview and no more?

Option #1: You let the library save the image as it does today, then crop the image yourself
Option #2: You fork the library and add in some sort of cropping logic as part of ImageCleanupTask

Related

How can I crop the live feed from the camera on each frame on Android?

I have the video preview from the camera which I want to crop.
But the cropping window is changing frame by frame (size and position of the cropping window).
How could I achieve this on Android (flutter, kotlin, java, nativescript,.. doesn't matter) to be able to show the live cropping results in a view and also be able to save the result to file?
I don't want the code, I just don't know which libraries and api's to use (link too documentation) and how the concept should be solved for this problem.
How to crop the live video from camera frame by frame and preview and save to file?
I created (partially) what I want in Javascript, just to show what I mean. In Javascript I use a HTML Video-tag (this could get the feed from the Webcam) then I create a Canvas and can read each frame of the video-tag as data and select exactly what I want from frame to frame.
let a = 10;
processor.computeFrame = function computeFrame() {
let frame = ctx.getImageData(a,0, this.width*0.5 +a, this.height); // here I use a moving window from left to right for the crop
ctx2.drawImage(frame, 0, 0); // and draw it back to the view (second canvas)
a +=0.1; //move the window
};
How can I solve this in Android?
I don't expect a fully working code... if you have any good articles, tutorials or documentation where I should start to read to achieve this, it would be perfect!
Interesting article:
https://engineering.depop.com/android-square-video-cropping-59b5edd69bce
https://www.programmersought.com/article/3222812179/
If you just wanted to crop preview, you could use a TextureView and update its transform matrix to match your desired crop rectangle.
If all you need is an occasional screen grab at the same resolution as preview for saving, you could use TextureView.getBitmap to read the cropped view to a Bitmap, and then save it.
If you need a higher-resolution or higher-quality capture, you'll need a separate output from the camera. Options are either capturing JPEG, decoding it, cropping the resulting Bitmap, and re-encoding it (assuming you want to save a JPEG, anyway), or capturing uncompressed YUV, cropping it, and then converting it to a Bitmap.
The CameraX Android support library might save you a lot of time in setting up the high-quality path, though I think you still need to do the cropping yourself for the output of the ImageCapture use case.

Android camera ensure fast response onPictureTaken

I have created a custom camera activity (pretty much followed the Android tutorial)
I implemented a SurfaceView to use a preview and an ImageView to display the image taken on OnPictureTaken
Picture taken takes a while to show up and differs from the preview in terms of aspect ratio, size, lighting, white balance. (probably I didn't set the params properly). The quality of the picture doesn't really matter to me. I just want the app to be responsive, ie still picture shows up immediately, and is identical to the preview.
So what I ended up doing was remove the ImageView and only have the SurfaceView. When the camera button is clicked, I stopPreview(). However, now I don't know how to save the SurfaceView content to bitmap/file. From what I read there isn't really a way to SurfaceView to return a bitmap.
What would be a better way to implement the camera? To reiterate, I need to be able to get a bitmap that is identical to the preview, and have that still image shown to the user immediately.

Want to build a camera app which can have Custom capture area on camera view

I want to capture a particular area from the camera.
I can build the custom preview, but that is not my actual requirement.
i want to have viewfinder like capture area on camera view and that should be the captured image size.
I was trying to do this a month back. The captured image or the preview image will not be pre-cropped. The trick is to identify your viewfinders rect and apply crop on the captured image.
You can head over to GitHub and clone my project Shaili-Android.
You will find the relevant camera code in CameraActivity.java
I have documented the project religiously. If you have issues, comment below.
Hope this helps :)

Android Crop during capturing image

i want to crop a image during capture not after capture.
like this image.
just replace save button with capture.
the rectangle should be realizable.just like the crop activity.
the thing i was doing was.
1st=capture image.
2nd=crop.
now i want to crop image during capture.
any help???
This is possible, Just think a different approach. Make a trick with camera preview. Taking a picture usually requires that your users see a preview of their subject before clicking the shutter. To do so, you can use a SurfaceView to draw previews of what the camera sensor is picking up. Now create a viewFinder for your camera capture activity. Now your make the compatible code to change the viewFinder size dynamically, which allow you to select the region. And finally save the Image from bitmap view inside ViewFinder. This is exactly what you want.
Please ask if you have not got my point. Best of luck.

Saving a camera's preview to a bitmap

I need a little help with getting my camera to work right.
What I'm trying to do is have the user take a picture that will then be used in another activity as the view's background. It is important not to have any skewing, and ideally the image would fill the entire background with the highest resolution possible.
I've been having a heck of a time trying to get the outputted picture of my camera to be oriented properly and be the same aspect of the display. So I took some time to think of exactly what I needed to do, and I don't think I need the normal saved image at all.
What I came up with is that I need a surface view to display the preview, and an overlay for some text and a capture button. When the user "takes the picture" it should autofocus, and then I need to capture the preview (under the screen overlays) to a bitmap to use in the other activity.
*Should I extend a SurfaceView for my preview and add it to a XML layout that contains the overlays?
*How do I save the SurfaceView's image to a bitmap?
Thanks.
Matt,
One basic question ,and excuse my naivety, wouldnt it just be easier to use the built in camera to the Android through an Intent? It is doable, I've done it before.
Apparently, there is no good way to convert the image format of the preview frames to a jpeg, so I ended up selecting the size for the camera to take by going through each of the camera's supported resolutions and getting the closest match the the screen aspect with the highest resolution.
Because the camera.setRotation method doesn't seem to do anything, I just rotate the image 90 with a matrix before saving it to the card if I am in portrait mode.

Categories

Resources