1

我已将 zxing 完全包含在我的应用程序中,以使其独立。它可以工作,但是相机是旋转的(我认为是逆时针旋转 90 度),并且它周围有一个奇怪的填充物。我的爪哇:

package it.mi.action.codmmunicator_2ddecoder;

import android.os.Bundle;
import android.widget.Toast;
import android.graphics.Bitmap;
import com.google.zxing.Result;
import com.google.zxing.client.android.CaptureActivity;

public class Lettore extends CaptureActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lettore);
}
@Override 
public void handleDecode(Result rawResult, Bitmap barcode) {
    Toast.makeText(this.getApplicationContext(), "Scanned code " +     rawResult.getText(), Toast.LENGTH_LONG);
}
}

和我的 xml(包括 zxing 的活动):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent" android:layout_height="fill_parent"     android:orientation="vertical">
<ImageView android:src="@drawable/head" android:layout_width="wrap_content"     android:layout_height="wrap_content" /> 
<FrameLayout android:layout_width="fill_parent" android:layout_height="250dip">
    <include layout="@layout/capture" android:toDegrees="90" />
</FrameLayout>
</LinearLayout>

填充是这样的:https ://dl.dropbox.com/u/16047047/Untitled-1.jpg

有人可以发布解决方案吗?

多谢

4

2 回答 2

2

它是 90 度旋转的,因为 Zxing 是专为风景而设计的。而且我认为您的应用程序是在纵向心情下工作的。

你可以试试这个ConfigurationManager.java

void setDesiredCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Log.d(TAG, "Setting preview size: " + cameraResolution);
    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
    parameters.set("orientation", "portrait");
    parameters.setRotation(90);
    if (camera != null)
        try {
            camera.setDisplayOrientation(90);
        } catch (NoSuchMethodError ex) {
        }
    setFlash(parameters);
    setZoom(parameters);
    // setSharpness(parameters);
    setSharpness(parameters);
    camera.setParameters(parameters);

}

注意:但这不是将他们的代码包含在您的项目中的方法。您需要通过 Intents 使用它。

于 2012-06-29T13:53:40.813 回答
1

您可以简单地将清单文件更改为只有横向模式。

<activity
        android:name="com.google.zxing.client.android.CaptureActivity"
        android:label="ZXing"
        android:screenOrientation="landscape"/>
于 2013-01-24T07:29:16.013 回答