Hi all,

I'm a newbie for Android programming and I'm making a code to control the 
camera by using API.
I'm struggling with the problem to map the screen coordination to camera's 
driver coordination for a long time.

(Development Env: Samsung Galaxy S3 & Eclipse)

I'd like to implement to show the rectangle in the screen when the user 
click the preview.
Actually there is no problem in establishing this but the problem is that
- I got wrong location with the coordination in the preview and the 
coordination in the camera focus area when I get the coordination to use 
getFocusArea

I translate the screen coordination to camera driver coordination by using 
the matrix.
Below is to initiate the matrix:
----------------------------
*

public static void prepareMatrix(Matrix matrix, boolean mirror, 
intdisplayOrientation, 
int viewWidth, int viewHeight) {
*

         // Need mirror for front camera.

         matrix.setScale(mirror ? -1 : 1, 1);

         // This is the value for 
android.hardware.Camera.setDisplayOrientation.

         matrix.postRotate(displayOrientation);

           // Camera driver coordinates range from (-1000, -1000) to (1000, 
1000).

            // UI coordinates range from (0, 0) to (width, height).

             matrix.postScale(viewWidth / 2000f, viewHeight / 2000f);

             matrix.postTranslate(viewWidth / 2f, viewHeight / 2f);

}  
I've got this code in the internet.

Below is to convert the coordination:
---------------------

*void* calculateTapArea(*int* focusWidth, *int* focusHeight, 
*float*areaMultiple, 
*int* x, *int* y, *int* previewWidth, *int* previewHeight, Rect rect) {

*            int* areaWidth = (*int*) (focusWidth * areaMultiple);

              *int* areaHeight = (*int*) (focusHeight * areaMultiple);

             *int* left = Util.clamp(x - areaWidth / 2, 0, previewWidth - 
areaWidth);

              *int* top = Util.clamp(y - areaHeight / 2, 0, previewHeight - 
areaHeight);

            RectF rectF = *new* RectF(left, top, left + areaWidth, top + 
areaHeight);

            *this*.gCoordinationConvertMatrix.mapRect(rectF);

           Util.rectFToRect(rectF, rect);

}

And finally below is to call above function. _x & _y is the screen 
coordination:
-----------------

        ArrayList<Area> mFocusArea = *new* ArrayList<Area>();

       mFocusArea.add(*new* Area(*new* Rect(), 1));

       ArrayList<Area> mMeteringArea =*new* ArrayList<Area>();

      mMeteringArea.add(*new* Area(*new* Rect(), 1));

       calculateTapArea(_100, _100, 1f, _x, _y, 

*        this*.gPreview.getWidth(), *this*.gPreview.getHeight(), 
mFocusArea.get(0).rect);

         calculateTapArea(_100, _100, 1.5f, _x, _y, 

*         this*.gPreview.getWidth(), *this*.gPreview.getHeight(), 
mMeteringArea.get(0).rect);

...... 
After this code, I just set the Auto Focus by setting the focus & metering 
area by using setFocusArea & setMeteringArea function.

Strange thing is I set the orientation as 'Landscape' in the manifest file 
so when I click the upper right corner when the phone vertically stand up, 
preview coordination returns 0,0 as expected. but after conversion, above 
function also returns 0,0. I think it should be -1000, -1000.

All codes above is from the Internet.
I thinks I'm doing wrong to display the focus area when the user click the 
preview screen.
If you know better idea or any hint then please let me know.

Thank you.

PS: Sorry for my poor English.

Brief Summary:
------------------
I'd like to get the correct focus area when the user click the preview 
area. But I got wrong focus area after setFocusArea to the camera after 
converting the preview coordination.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to