2012-05-04 3 views
1

마다 하나씩. 나는 안드로이드 개발자입니다. 표시되는 이미지의 가운데 부분에서 이미지를 매트릭스로 확대하고 싶습니다. 그래서 이미지를 매트릭스로 크기를 조정했습니다. 그런 다음 계산 된 포인터로 이동했습니다. 그러나 응용 프로그램이 제대로 작동하지 않습니다. 올바른 센터를 찾을 수 없으므로 제대로 움직입니다. 이유가 무엇인가요? 문제를 찾을 수 없습니다.매트릭스를 사용하여 디스플레이 중심에서 이미지 배율

코드가 이어졌다.

당신이 센터 zoomIn 및 zoomOut에 대한 샘플 코드 매트릭스로 이미지 뷰가 있었나요

  matrix.reset(); 
      curScale += 0.02f; 
      orgImage.getHeight(); 
      w = orgImage.getWidth(); 
      matrix.postScale(curScale, curScale); 
      rtnBitmap = Bitmap.createBitmap(orgImage, 0, 0, w, h, matrix, true); 
      curImageView.setImageBitmap(rtnBitmap); 
      Matrix curZoomOutMatrix = new Matrix(); 

      pointerx =(int) ((mDisplayWidth/2 - curPosX) * curScale); 
      curPosX = - pointerx; 
      pointery =(int) ((mDisplayWidth/2 - curPosY) * curScale); 
      curPosY = - pointery; 

      Log.i("ZoomOut-> posX = ", Integer.toString(curPosX)); 
      Log.i("ZoomOut-> posY = ", Integer.toString(curPosY)); 
      curZoomOutMatrix.postTranslate(curPosX, curPosY); 
      curImageView.setImageMatrix(curZoomOutMatrix); 
      curImageView.invalidate(); 

? 누가 설명 할 수 있습니까? 도와주세요.

답변

2

또는 내 잘못입니다. 먼저 원본 이미지에서 이미지의 크기를 조정합니다. 그래서 이미지는 (너비, 높이) * 스케일입니다. 그러면 중심으로 표시되는 점의 절대 위치를 계산합니다. 그런 다음 ImageView를 뷰가있는 계산 된 위치로 이동하십시오. 내 잘못이야. 뷰 위치를 계산할 때부터 현재 위치에서 위치를 변경합니다. 그래서 크기를 조정하면 위치는 <original position> * <now scale>이 아닙니다. 그것은 <original position * <scale> * <now scale>이었고 결과는 이상한 위치였습니다. 그래서 원래 위치에서 중심 위치를 계산하기 위해 다시 만듭니 다.

그 모드는 다음과 같습니다.

public void calculate(float offset) { 

    float tmpScale = curScale - offset; 
    float orgWidth = (mDisplayWidth/2 - curPosX)/tmpScale; 
    float orgHeight = (mDisplayHeight/2 - curPosY)/tmpScale; 
    int tmpPosX = (int)(mDisplayWidth/2 - orgWidth * curScale); 
    int tmpPosY = (int)(mDisplayHeight/2 - orgHeight * curScale); 

    curPosX = tmpPosX; 
    curPosY = tmpPosY; 

    Matrix matrix = new Matrix(); 
    matrix.postTranslate(tmpPosX, tmpPosY); 

    curImageView.setImageMatrix(matrix); 
    curImageView.invalidate(); 
} 

감사합니다. 모든 사람.