Is it possible to take a thumbnail photo using the camera? I see methods like getJpegThumbnailQuality but I don't see anything for taking the actual thumbnail. I must do this using the Camera API and not using an Intent.
By any means, Camera itself will not directly produce a Bitmap of thumbnail size. Most devices have limited set of picture resolutions for camera. However you can create another scaled down bitmap from the picture camera provides you.
Related
If I use standard camera via Intent to capture image:
Open Camera:
val takePicture = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
if (takePicture.resolveActivity(packageManager) != null) {
startActivityForResult(takePicture, TAKE_PICTURE)
}
Camera Preview
Result display on ImageView
If I use Camera2 API at: git: https://github.com/googlesamples/android-Camera2Basic
Result of Image not display portrait
Camera 2 Preview
Result display on ImageView
My code display Image:
val bitmap = BitmapFactory.decodeFile(file.toString())
imagePreview.setImageBitmap(bitmap)
}
How setting Camera2 API to display result the same standard camera?
In Camera2Basic example, the ImageSaver does not rotate the captured JPEG with regards to device orientation. Instead, Camera2BasicFragment.captureStillPicture() sets CaptureRequest.JPEG_ORIENTATION, which is only a recommendation for the camera firmware.
Camera devices may either encode this value into the JPEG EXIF header, or rotate the image data to match this orientation. When the image data is rotated, the thumbnail data will also be rotated.
Most often, this recommendation 'only' sets the header, but some devices miss even that. See a recent article on this feature and its reliability.
Please note that the EXIF orientation tag is not respected by all viewer software, therefore often the stock Camera applications do rotate the actual JPEG to default orientation.
Your code that loads the captured picture to ImageView currently ignores this tag. You can use ExifInterface.getAttributeInt(TAG_ORIENTATION) to extract the orientation from the file or input stream. Or, if you capture an image and immediately display it, you can get device orientation directly from the sensor. Now it's time to decide if the camera stored the image as portrait (i.e. width is smaller than height), or as landscape, in which case it's your duty to rotate it for display. Don't rotate the bitmap according to this orientation. Instead, you can call imagePreview.setImageMatrix() to display the image correctly.
By the way, please don't decode the JPEG to full-scale bitmap in memory if you only need it to be passed to your ImageView: this may consume too much RAM. The easiest one-liner is to call setImageURI() instead.
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.
I'm an intermediate android programmer. I've a simple application created for learning camera. My app is using camera.takePicture() method to register callbacks for JPEG callback and eventually capture the picture.
But I feel that it may also be possible to capture the image using setOneShotPreviewCallback() and providing a callback.
My question is:
Will there be any differences in image quality between the 2 approaches?
Any additional things to be taken care of when trying to construct image using setOneShotPreviewCallback()?
Thanks in advance.
takePicture() uses (potentially) the camera's full resolution. The preview gives you the image shown on screen which is more usually the screen's resolution. The picture will be higher resolution in general and higher quality. Note that you get something like JPEG-encoded data from the picture callback, but raw image buffer data in the preview callback.
The person is using the surface view to capture the image by camera its quality will be good
Is it possible to programmatically take a picture in full/high resolution? I use the camera preview and surface with some custom overlay content. The problem is that the takePhoto function returns data only in preview size low resolutions.
Even if I check the getSupportedPictureSizes the resolutions that are listed are far from the 5Mpix that is the max supported resolution by the system camera. So the question is can I take a photo in max resolution and use custom camera preview or I have to call the system camera Intent to have a full res photo?
Yes you can, you should setPictureSize(), see https://github.com/alexcohn/JBcamera for example.
PS Thanks, Benjamin, for drawing my attention back to this question. if I understand correctly, the author was upset with the resolution of data array returned from IMAGE_CAPTURE intent. But this is only the thumbnail; the actual hi-rez imagis writn to file. You can find this Jpeg file and load it into your app, in onActivityResult()
By default I think it is set to a low resolution. To change this call MediaStore.EXTRA_OUTPUT in your intent. See here for more detail:
http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE
I want to change the size of an image taken by the camera say 600x800. I am successfully doing so and its working fine but I also want to change the byte size or you can say memory as well. Like the photo resizer app https://play.google.com/store/apps/details?id=com.xllusion.app.photoresizer&feature=search_result on google play. For example if I take a photo on this app and change the resolution to 600x800. It creating this resolution photo simply with 23kb(no quality compromise) where as original photo was of 600kb. Can somebody help???