Android-Touch Area Focus Region

Source: Internet
Author: User

Old Long wanted to find out about different clicks in different places of focus, but has not been found, and now the project needs this function, and run out to find, and finally find out ~ ~ More about focus on autofocus.

Needless to say, the direct to dry, mainly setfocusareas way to achieve.

Each diagonal area is a rectangle with a specific weight. The direction is related to the direction of gravity sensing. This direction is not affected by the setdisplayorientation (int) setting. The coordinates of the rectangle range from 1000 to 1000, ( -1000,-1000) is the upper-left corner (1000,1000) is the lower-right point. The length or width of the focus area cannot be 0 or negative, while the weight value range is 1-1000, and the weights are equally divided by the rectangular range of pixels, which means that the same weighted focus area has a small effect on the overall focus.

Code
PrivateRect Calculatetaparea (floatXfloatYfloatcoefficient) {        floatFocusareasize = 300; intAreasize = float.valueof (Focusareasize *coefficient). Intvalue (); intCenterX = (int) (X/getresolution (). width-1000); intCenterY = (int) (Y/getresolution (). height-1000); intleft = Clamp (CENTERX-AREASIZE/2,-1000, 1000); inttop = Clamp (CENTERY-AREASIZE/2,-1000, 1000); RECTF RECTF=NewRECTF (left, top, left + areasize, top +areasize); return NewRect (Math.Round (Rectf.left), Math.Round (Rectf.top), Math.Round (Rectf.right), Math.Round (Rectf.bottom))    ; }    Private intClampintXintMinintmax) {        if(X >max) {            returnMax; }        if(X <min) {            returnmin; }        returnx; }     Publiccamera.size getresolution () {camera.parameters params=mycamera.getparameters (); Camera.size s=params.getpreviewsize (); returns; }

This method is called in the Ontouch event.

I'm the dividing line of the king of the land Tiger.

Android-Touch Area Focus Region

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.