안녕하세요?

이제 막 개발 공부한지 한달정도 되어 가는 신참입니다.

 

지금 카메라 Control을 구현하고 있는 중인데요.. API써서요..

Preview를 클릭하면 OnTouch Event로 좌표를 읽어와 SetFocusArea를 Parameter를 통해 설정하려고 하는데,

정확하게 맵핑하는 방법을 몰라 질문을 드립니다.

 

이래 저래 Search를 통해 Matrix를 설정해서 Focus Area를 설정하는 것같아 그렇게 하고 있습니다.

아참 개발은 Galaxy S3로 직접 테스트를 하고 있고, Eclipse사용중이구요...

 

Preview Click시 Auto focus Area를 네모모양으로 표시하는 중, Preview 화면과 실제 Driver Coordination이 값이 틀려 클릭한 위치와

실제 카메라 Driver Coordination에 저장된 값이 틀려 Focus위치가 다르게 나옵니다.

 

아래는 Matrix를 초기화 설정하는 부분이구요

public

static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation, 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);

}  <--- matrix값에는 gCoordinationConvertMatrix 변수값을 설정합니다.

 

public

아래가 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);

}

 

위 부분을 호줄하는 부분은 아래와 같습니다.

_x와 _y는 preview에서 Click한 위치입니다.

--------------------------------------------------------------------

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);

......

이후는 파라미터 읽어서

setFocusAreas와 setMeteringAreas를 설정하고 새로 AutoFocus를 설정해 줍니다.

 

Source는 많이들 보신 Source일겁니다.

 

근데 왜 전 안될까요... ㅠ,.ㅠ

 

전 manifest화일에서 카메라  Orientation을 Landscape모드로 설정해 놓았습니다.

그래서 Preview를 클릭하면 (세로로 세웠을때) 오른쪽 맨위에가 0,0 이구요 Matrix로 변환시

Camera Driver Coordination는 0,0입니다. 사실 Matrix를 잘 몰라 왜 오른쪽 맨 위에가 0,0이 나오는지도 모르겠습니다.

제가 메뉴얼 보기엔 -1000, -1000 이 나와야 할것 같은데요..

 

뭔가 큰 실수를 하고 있는것 같긴 한데.. 뭐가 문젠지 잘 모르겠습니다.

 

고수님들의 작은 멘트 하나가 신참을 살립니다. 벌써 몇일째 고민중이랍니다.

그럼 훈수 하나 부탁드립니다.

 

이 방법이 아니어도 괜챦습니다. 혹시 좀더 간단한 방법이라든지 제가 뭐 참고할 만한 사항이라도 있으시면 글 남겨 주시면 감사하겠습니다.