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