My company has a need to print a timestamp on images taken on a droid. Another developer mentioned that we could wrap the entire functionality of the stock camera, then once a photo is taken, embed the timestamp on it. Can this be done, and if so, how simple/complex would it be?
Pretty simple actually. Definitely way simpler then writing a camera app from scratch.
Here is a short overview to give you a few keywords:
You need to fire a ACTION_IMAGE_CAPTURE intent,
this launches the devices camera app and prompts the user to take a picture (stock app or not doesn't even matter). When the picture is taken it will return to your app¹. At this point you'll get a file URI of the taken image that points to a JPEG usually.
Once you have that, load the image via the BitmapFactory into a Bitmap object and edit it by using a Canvas. You can use Canvas.drawText() to draw the text. Then store it where you need it, send it off the device or do whatever you want with it. And that's all the magic.
¹ here is a small example how to do that, found via google, there are plenty more out there
Related
I'm using a chooser to allow the user to pick a photo from his gallery or take a new one using his camera (I copied the code from this answer).
Picking an image from the gallery works perfect. The problem is that when I capture an image with the camera It's not returning to the app and just stays in the confirmation screen...
I actually don't even need this screen to be displayed in the first place...
Can I somehow disable it or (if not) just make the Done button work?
Thanks in advance!
Can I somehow disable it
No.
just make the Done button work?
Contact the developers of your camera app, and point out the bug. Perhaps someday they will fix it.
You are using ACTION_IMAGE_CAPTURE. This launches a third-party camera app, to take a picture. There thousands of Android device models. These ship with hundreds of different pre-installed camera apps, and there are many more available for download from the Play Store and elsewhere. Any could be the one that handles a given ACTION_IMAGE_CAPTURE request, and any of them can have bugs.
I need to scan a special object within my android application.
I thought about using OpenCV but it is scanning all objects inside the view of the camera. I only need the camera to regognize a rectangular piece of paper.
How can i do that?
My first thought was: How do barcode scanners work? They are able to regognize the barcode area and automatically take a picture when the barcode is inside a predefined area of the screen and when its sharp. I guess it must be possible to transfer that to my problem (tell me if im wrong).
So step by step:
Open custom camera application
Scan objects inside the view of the camera
Recognize the rectangular piece of paper
If paper is inside a predefined area and sharp -> take a picture
I would combine this with audio. If the camera recognized the paper make some noice like a peep or something and the more the object is fitting the predefined area the faster the peep sound is played. That would make taking pictures for blind people possible.
Hope someone got ideas on that.
OpenCV is an image processing framework/library. It does not "scan all objects inside the view of the camera". By itself it does nothing and yet it gives the use of a number of useful functions, many of which could be used for your specified application.
If the image is not cluttered and nothing is on the paper, I would look into using edge detection (i.e. Canny or similar) or even colour blobs (even though colour is never a good idea, if your application is always for white uncovered paper, it should work robustly).
OpenCV does add some overhead, but it would allow you to quickly use functions for a simple solution.
I understand that to take video of the application you need to have your phone rooted in android. What feature puts this restriction?
Workaround
I want to know how feasible this is? Take screenshots of the UI on regular intervals(very quick intervals) and convert those pictures into a video.
NOTE
By screenshot I mean the area of only my application's layout. I want to take rapid screenshots of the layout and then convert it into a video. If it is possible, when saving the current state of the layout in a bitmap, will it do so in a UI thread?
if you are trying to capture the current application activity you can use this code in a thread with a timer.
RelativeLayout rl1 = (RelativeLayout)findViewById(R.id.relative_layout_1);
View v1 = rl1.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
and you can make a video. refer This Link
You can use this solution if you want to capture your own application activities.
Capturing the phone's entire screen is only possible using the the READ_FRAME_BUFFER permission which allows system (non 3rd party!) apps to take screenshots. This is why this solution works for rooted devices only. You can find a more detailed explanation here.
If you are just looking to capture some fluid images of your app in action, you might just try video capturing/taking screenshots of your app on your desktop while running the app in the Android emulator.
I am wondering whether it is possible to set the size of the Android camera's frame through the native camera app. The goal is to be able to take pictures of a certain format (where height == width). I have looked at the official documentation but it seems that the only parameter that can be passed to the intent (ACTION_IMAGE_CAPTURE) is EXTRA_OUTPUT to define the path in which the picture will be saved.
Any idea? (If it's not possible I guess I'll need to let the user crop the picture to make it fit in a given square).
Thanks!
You can customize it, as long as this is format offered by camera service. (See camera API)
But even this does not mean that desired resolution is actually supported. When you are using intent, you are invokinng installed camera appliaction - it may provide some ways of customisation via intent, but it is not defined in standart and not portable between different vendors.
Your best option is to post process image and crop it after it is taken
so, the way I read the documentation, using EXTRA_OUTPUT tells the camera to save the file in a specific location. That's great, but it also says to get a full size image. That's not so great.
How can I get just a small image but still specify the filename?
After trying to work with the built-in Camera activity for some time now I can advise you not to expect anything good from it because:
built-in activity differs from version to version. For example in 2.2 emulator it even crashes when you try to take a (dummy) picture.
Camera activity on real devices like Samsung Galaxy S is different, i.e. it not just looks different, it has different code and set of bugs.
Original built-in Camera activity has CROP feature, but it is not part of the public API and thus it is not good idea to use it.
So far I fount that to be safe when working with camera I need to:
- create my custom camera activity that misses the fancy stuff like filters, etc but is more configurable (I don't have it yet). I've tried to find third party Camera App but every one of them seems to be targeted at normal users not developers, i.e. has many "cool" features but it is slow / bloated / buggy / has bad UI.
- create thumbnail images by myself outside of the Camera activity (for more control).
I really hope that I am missing something here and someone will correct me in the comments with appropriate solution...
I ended up just dealing with the large images by always scaling on the read. It would have been nice not to have to do that as I read in more than one place, but ...oh well...
problem solved, although far from elegant.