3

ImageView의 밝기, 대비, 채도 및 색조를 변경하고 있습니다. 나는 그것에 대해 많이 조사했다.ImageView에서 두 개의 ColorMatrix를 병합하거나 동시에 두 개 이상의 ColorMatrix를 적용하십시오.

ColorMatrix와 작동하는 코드가 있습니다.

는 [1] 밝기를 들어 ColorMatrix 제대로 작동

float brightness = (-50F * 1.5F); 
    ColorMatrix cmB = new ColorMatrix(); 
    cmB.set(new float[] { 1, 0, 0, 0, brightness, 
    0, 1, 0, 0,brightness, 
    0, 0, 1, 0, brightness, 
    0, 0, 0, 1, 0 }); 
    myImageView.setColorFilter(new ColorMatrixColorFilter(cmB)); 

같은 몇 가지 일이다.

는 [2]대비를 ColorMatrix도 제대로 작동 뭔가 다른이다.

그러나이 ColorMatrix는 모두 입니다. 마지막으로 적용한 ColorMatrix의 효과를 의미합니다 ImageView의 장면입니다. 정확히 수행하기 때문에 은 적용된 이전의 효과를 제거합니다. ColorMatrix 및 설정은 마지막으로 ColorMatrix를 적용합니다.

이제 ColorMatrix를 모두 동시에 병합하거나 혼합하고 싶습니다. Brightnrs/Saturation/Hue의 ColorMatrix 효과에 Contrast의 ColorMatrix를 적용하고 싶습니다.

답변

2

두 개의 컬러 매트릭스를 적용하려면 두 개를 함께 곱하면됩니다. 당신은 다음 컬러 매트릭스 A, 및 컬러 매트릭스 B가있는 경우

는 : 난 그냥 눈치

C = B * A; 
outpixel = C * inpixel 

그 원래 (5 × 4 행렬 것을

outpixel = B * A * inpixel 

편집에 해당 나는 그들이 4x4라고 생각했다). 이후에 직접 곱할 수 없기 때문에 곱하기 (두 행을 모두 5x5로 만들기) 전에 5 번째 행 (0,0,0,0,1)을 두 행렬에 모두 추가하고 5 번째 행을 버리는 것이 적절하다고 생각합니다. 곱하기.

0

당신은 그렇게 여러 행렬을 적용 할 수

ColorMatrix colorFilterMatrix = new ColorMatrix(); 
colorFilterMatrix.postConcat(getContrastMatrix(contrast)); 
colorFilterMatrix.postConcat(getBrightnessMatrix(brightness)); 

imageView.setColorFilter(new ColorMatrixColorFilter(colorFilterMatrix)); 
관련 문제