2015-01-15 2 views
1

Android Studio에서 프로젝트를 만들고 zxing 라이브러리 2.3을 추가했습니다. 세로 모드에서만 스캔하고 디코딩하고 싶습니다. 나는이 설명서 Zxing Camera in Portrait mode on Android을 읽었으나 이제는 세로 모드로 바코드를 디코딩 할 수 없습니다. 는 나는 또한 세로 매니페스트 모드와 CameraConfigurationManager.java에이 코드를 추가하여 다른 방법에서이 문제를 해결하기 위해 노력 :Zxing이 세로 모드에서 올바로 작동하지 않습니다.

parameters.set("orientation", "portrait"); 
    parameters.setRotation(90); 
    if (camera != null) 
     try { 
      camera.setDisplayOrientation(90); 
     } catch (NoSuchMethodError ex) { 
     } 

프로그램이 세로 모드에서 시작을하지만 난 내 전화를 회전 할 때, 어떤 바코드를 디코딩 didnt는 90도, 프로그램 디코딩 바코드, qr 코드 이미지 캡처 및 90도 회전시, 내가 전화를 돌릴 때 프로그램 디코드 바코드.

+1

나는 도서관 https://github.com/xiaowei4895/zxing-android-portrait으로이 프로젝트를 추가하여 내 문제를 해결, – Kirill

+0

당신이 대답 할 수 ? –

답변

0

저는 zxing zxing 2.3을 사용했으며 저의 솔루션은 저에게 효과적이었습니다.

CameraConfigurationManager 클래스

1, setDesiredCameraParameters 방법 뾰족한 행 아래 코드 아래 추가

-> Camera.Parameters 파라미터 = camera.getParameters(); CameraManager 클래스

if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { 
     camera.setDisplayOrientation(90); 
} 

2, getFramingRect 메소드 CameraManager 클래스

int width = MIN_FRAME_WIDTH; int height = MIN_FRAME_HEIGHT; 
if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) { 
    int tmp = 7 * screenResolution.x/8; 
    width = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : (tmp);     
    tmp = 1 * screenResolution.y/3; 
    height = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : ((tmp) > MAX_FRAME_HEIGHT ? MAX_FRAME_HEIGHT : (tmp)); 
}else{ 
    // Original Code 
    width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, > MAX_FRAME_WIDTH); 
    height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); 
} 

3 아래와 같이 코드를 대체 getFramingRectInPreview 방법

DecodeHandler 클래스
if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) { 
    rect.left = rect.left * cameraResolution.y/screenResolution.x; 
    rect.right = rect.right * cameraResolution.y/screenResolution.x; 
    rect.top = rect.top * cameraResolution.x/screenResolution.y; 
    rect.bottom = rect.bottom * cameraResolution.x/screenResolution.y; 
}else{ 
    // Original code commented 
    rect.left = rect.left * cameraResolution.x/screenResolution.x; 
    rect.right = rect.right * cameraResolution.x/screenResolution.x; 
    rect.top = rect.top * cameraResolution.y/screenResolution.y; 
    rect.bottom = rect.bottom * cameraResolution.y/screenResolution.y; 
} 

4 디코드 방법 아래와 같이 코드를 대체 아래에 코드를 추가하십시오.

-> Resu lt rawResult = null;

if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){ 
     byte[] rotatedData = new byte[data.length]; 
     for (int y = 0; y < height; y++) { 
      for (int x = 0; x < width; x++) 
       rotatedData[x * height + height - y - 1] = data[x + y * width]; 
     } 
     data = rotatedData; 
     int tmp = width; 
     width = height; 
     height = tmp; 

    } 

당신은 세로 모드에서만 작동하려면 당신은 모든 조건을 제거 할 수 있습니다 내 작업 코드

http://www.compyutech.co.in/repo/zxing-dynamic.zip

을 찾아주세요. 이 당신을 도울 것입니다

희망 ....

관련 문제