【问题标题】:ZXing completely included, but camera rotatedZXing 完全包括在内,但相机旋转
【发布时间】:2012-06-28 15:35:36
【问题描述】:

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

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

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

非常感谢

【问题讨论】:

  • 从您的应用程序中删除它并与 Intents 集成。这是该系统的使用方式。我保证,这会让你的头痛大大减少。
  • 但我不能......它必须出现在我的视图中,而不是新的意图(在全屏的新视图中出现)。如果我可以在我的观点中整合一个意图,那没关系,但我不知道如何。换句话说:这些东西必须像我的屏幕一样:看到下面有图像吗?并且相机是集成的?
  • 为什么“必须”出现在您自己的视图中?创建 BarcodeScanner 的人做得非常出色。并为您提供了一种将其与您自己的应用程序集成的简单方法。通过尝试将其源代码复制/粘贴到您的应用程序中,您正在“向上游泳”。这样做会带来更多的麻烦。
  • 因为我必须这样做。我的客户想要它。在 iphone 应用程序中,编码器做到了,我没有复制源代码,我通过 ecplipse 中的库将其集成
  • 没有办法在我的视图中抛出一个意图?我想一定有办法……

标签: android include frame qr-code zxing


【解决方案1】:

它是 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 使用它。

【讨论】:

  • 没错,您需要实现自己的纵向模式布局,因为应用程序不是纵向模式。您不能也不应该复制项目 UI。 camera.setDisplayOrientation(90); 本质上是需要的线,但是当您考虑到某些摄像头没有以 90 度安装并且有前置摄像头需要翻转时,它确实会变得更复杂。
【解决方案2】:

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

<activity
        android:name="com.google.zxing.client.android.CaptureActivity"
        android:label="ZXing"
        android:screenOrientation="landscape"/>

【讨论】:

  • 这很有用。我在清单中将 CatureActivity 方向设置为横向,效果很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多