2016-05-18 3 views
0

Je suis les instructions étape par étape au Zxing Camera in Portrait mode on Android pour afficher le portrait pendant que l'utilisateur utilise la caméra zxing.Zxing (v3.2.0) Appareil photo en mode portrait fixe utilisant l'éclipse

Mais cela ne fonctionnera pas. Le scanner est toujours apparu en mode paysage. Je pense que c'est parce que j'utilise la dernière version (v3.2.0) de Zxing et l'instruction est obsolète.

Comment cela peut-il être fait dans v3.2.0 Zxing?


Quoi qu'il en soit, voici les étapes que j'ai essayé:

  1. Modifier buildLuminanceSource (..) DecodeHandler.java

code:

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]; 
} 
int tmp = width; 
width = height; 
height = tmp; 

PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height); 

  1. Modifier getFramingRectInPreview() dans CameraManager.java

code:

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; 

  1. Modifier initFromCameraParameters (Dans Zxing (v3.2.0), je ne trouve pas le code suivant

code:

//remove the following 
if (width < height) { 
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); 
int temp = width; 
width = height; 
height = temp; 
} 

  1. Ajouter une ligne suivante pour faire pivoter la caméra dans setDesiredCameraParameters (...) dans CameraConfigurationManager.java

Code:

camera.setDisplayOrientation(90); 

  1. Dans mon projet, modifier AndroidManifest.xml

code:

android:screenOrientation="portrait" 

Répondre

0

Après avoir fait des essais et erreurs pour quelques jours, voici ma solution de travail:

Il faut un travail supplémentaire, disons l'étape 6. Toujours définir l'orientation portrait, peu importe quoi. Et ça a marché.


Étape 6. Modifier onResume dans CaptureActivity.java

if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) { 
    //setRequestedOrientation(getCurrentOrientation()); // mark this line 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
} else { 
    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // mark this line 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
}