Android Camera app

Source: Internet
Author: User

Objective

Android in the design of the architecture, the use of mashups (mashup) of the design concept, that is, everything is set up, their own writing is a component, others provide is also components, when used as long as they meet the relevant protocol can be regarded as their own components. For example, the system provides cameras, contacts and so on can be directly used. Take a look at what the camera is about today.

Simply call the camera

If our requirement is simply to call the camera directly without having to do any subsequent processing, then this is very simple, by passing a intent object, you can call the camera component directly, as shown below:

Intent intent=New  Intent (Android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Mcontext.startactivity ( Intent);

So we have the camera components tuned out and then we can use the camera normally.

Get the contents of a camera

In the previous section we simply used the camera, while the contents of the photos are stored in the default path, but more often we need not only to call the camera to take pictures, but also to do the following processing,
For example, to put down the content in our designated content area, such a need for a little more trouble. When you call the camera, you need to start a camera activity with a return value.
The returned photos are then processed in the receive interface, as follows:
Calling code

Intent intent=New  Intent (Android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Activity.startactivityforresult (Intent,

Using the code above, a camera activity with a return value is started, and the return interface is called when the camera is finished, and we are working with the photo content in this interface. As shown below
Return code

protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        Super. Onactivityresult (Requestcode, ResultCode, data); Switch(requestcode) { Case1:                        //Get PhotosBundle Extras =Data.getextras (); Bitmap Bitmap= (Bitmap) extras.get ("Data"));  Break; default:             Break; }            }

Through the above code we can get to the camera captured content, is a bitmap object, and then we can use this object, when we found that this picture is not the original photo, but after the compressed photos, if we can meet our needs that is OK, If we need to get to the original photo, we need to use the following content.

Get the original photo

If you want to get the original photo, you need to make further settings when passing the intent object, and you need to save the specified original photo to the specified path, as shown below

    New File ("/sdcard/demo/temp");     if (! file.exists ()) {        file.mkdirs ();    }         New File (tempdir, "test");        Intent Intent=new  Intent (Android.provider.MediaStore.ACTION_IMAGE_CAPTURE);     Uri u=uri.fromfile (imgfile);     // specify the path to the    

So the calling code is written, and the camera prints the original photo to the/sdcard/demo/temp/test file.

Using the original photo

This is easy, knowing the path we can access and process it in various ways, here's one way.

protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        Super. Onactivityresult (Requestcode, ResultCode, data); Switch(requestcode) { Case1:                        //Get PhotosUri uri = Data.getdata ();//get to Yes picture pathContentresolver CR = This. Getcontentresolver (); Bitmap Bitmap=NULL; Try{bitmap=Bitmapfactory.decodestream (Cr.openinputstream (URI)); } Catch(FileNotFoundException e) {e.printstacktrace (); }                           Break; default:             Break; }

So we have got this bitmap, follow-up on the casual use.

Postscript

This article is a brief introduction to the use of the camera, of course, you can also customize the camera interface to complete, and so on, I believe that this article is a brief introduction will have a rough outline, as for
The extent to which it is used depends on the specific requirements and then further customization based on the API.
URI: The Uniform Resource Identifier (Uniform Resource Identifier, or URI) is a string that identifies the name of an Internet resource. It can identify various types of resources, such as our common HTTP resources, as well as FTP resources, which in this article represent a path resource.

Original address: http://www.cnblogs.com/luoaz/p/4148851.html

Android Camera app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.