2012-06-28 38 views
1

我已经完全包括在我的应用程序zxing,使其单机。 它的工作原理,但相机旋转(我认为90逆时针),它有一个奇怪的填充区域。 我的Java:ZXing完全包含,但相机旋转

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(这需要斑马线喜欢的活动包括):

<?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

可有人张贴解决方案?

非常感谢

+3

将其从您的应用程序中删除并与Intents集成。这是系统意图使用的方式。我保证,这会让你头痛得少得多。 – FoamyGuy

+1

但我不能......它必须出现在我的视图中,而不是以新的意图出现(在全屏中进入新的视图)。 如果我可以将意图整合到我的观点中,那很好,但我不知道如何。 换句话说:事情必须保持像我的屏幕:看到下面有一张图片?并且相机是集成的? – Zak

+0

为什么“必须”出现在您自己的视图中?创建BarcodeScanner的人做了很棒的工作。并为您提供了一种简单的方法来将其与您自己的应用程序集成。您正尝试将其源代码复制/粘贴到您的应用中,从而“向上游泳”。它会造成比它的价值更大的麻烦。 – FoamyGuy

回答

2

它旋转90度,因为斑马线设计为只能景观mood..And我瘦你的应用程序工作在纵向的心情。

您可以在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使用它。

+0

这是正确的,您需要实现自己的肖像模式布局,因为应用程序不是肖像模式。你不能也不应该复制项目UI。 'camera.setDisplayOrientation(90);'本质上是需要的线条,但当你考虑到一些摄像机没有安装在90度时,它确实变得更加复杂,并且有前置摄像机可以翻转。 –

1

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

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

这很有用。我在清单中将CatureActivity方向设置为横向,并且工作正常。 –