2013-07-12 4 views
7

나는 SO가 매트릭스 질문으로 가득차 있다는 것을 알고 있습니다. 그러나 나는 완전히 설명되어있는 질문을 찾을 수 없습니다. 모든 ImageView에는 스케일링, 회전 및 위치를 담당하는 행렬이 있습니다. 하지만이 같은 매트릭스 사용하여 이미지를 회전 할 수 없습니다 이유 : 나는 새로운 매트릭스마다의 I를 만들어야 할 이유ImageView Matrix의 사용법을 알고 싶습니다.

ImageView img = (ImageView)findViewById(R.id.some_imageview); 
img.setScaleType(ScaleType.Matrix); 
Rect bounds = img.getDrawable.getBounds(); 
Matrix rotationMatrix = new Matrix(); 
rotationMatrix.postRotate(180f, bounds.width()/2, bounds.height()/2); 
img.setImageMatrix(rotationMatrix); 

을 :

ImageView img = (ImageView)findViewById(R.id.some_imageview); 
img.setScaleType(ScaleType.Matrix); 
Rect bounds = img.getDrawable.getBounds(); 
img.getImageMatrix().postRotate(180f, bounds.width()/2, bounds.height()/2); 

여러 답변이처럼 할 제안을 회전하고 싶습니까? 또한 두 번째 예제에서 Matrix를 설정 한 경우 rotationMatrix을 다시 설정하면 다시 회전하지 않는 이유는 무엇입니까? 원래 학위를 받고 싶으면 평범한 매트릭스를 설정할 수 있습니다.

img.getImageMatrix().postRotate(180f, bounds.width()/2, bounds.height()/2); 

작동하지 않습니다하지만 왜 다시, 나는 이해가 안 돼요.

참고 : 인해 코멘트 내가 질문을 의미하는 새로운 매트릭스 매번 작성해야하는 이유는 요구했다

이유에 : 나는 또한

EDIT 차이를 관찰하지 않고 setRotate 방법을 시도했다 매트릭스를 사용할 수 없습니다. 또한 내가 일을 생각하는 것은 (이 사실은하지 않습니다, 너무)이이었다

ImageView img = (ImageView)findViewById(R.id.some_imageview); 
img.setScaleType(ScaleType.Matrix); 
Rect bounds = img.getDrawable.getBounds(); 
Matrix rotationMatrix = new Matrix(); 
rotationMatrix.postRotate(180f, bounds.width()/2, bounds.height()/2); 
img.setImageMatrix(rotationMatrix); 
//works until here. 

//Then after that successful call 

//assumed to get my Matrix back, which is rotated by 180 degrees 

Matrix matrix = img.getImageMatrix(); 
Rext bounds = img.getDrawable().getBounds() 
//rotate again at 90 degree. It should be now rotated 270 degrees (180 from before, plus 90 now) 
matrix.postRotate(90f, bounds.width()/2, bounds.height()/2); 
//unfortunately NO effect! 
img.setImageMatrix(matrix); 
+0

getImageMatrix에서 반환 한 행렬을 사용하지 말라는 문서가 나와 있습니다. 보세요 [여기] (http://developer.android.com/reference/android/widget/ImageView.html#getImageMatrix()) – Blackbelt

+0

@blackbelt 설명을 요청했습니다. 왜이 매트릭스를 제자리에 사용해서는 안되며, 적어도 null이 아닌 경우 ... 특히 내가 직접 설정 한 경우 ... –

+1

실제로 "내가 회전 시키길 원할 때마다 새 매트릭스를 만들어야합니까?"라고 물었습니다. – Blackbelt

답변

1

는 매트릭스 계산이 적용되는 setImageMatrix() 메소드처럼 보이는 source에서 찾고있다. 이후에이 행렬을 사용할 경우 (즉 getter로 구한 후) setter 메서드에서 계산을 수행하면 아무런 영향을 미치지 않습니다.

관련 문제