Zxing 豎屏切換 android

來源:互聯網
上載者:User

標籤:zxing   二維碼   豎屏   android   改豎屏   

Zxing 豎屏切換  android

在google上下載的ZxingDemo 為橫屏狀態  

我簡單的在Androidmanifest.xml把Activity換成豎屏android:screenOrientation="portrait"

螢幕雖然正了 但是螢幕上顯示的拍攝畫面還是橫著的 

查了一些網上的資料   結合自己手工調試 

在這裡總結分享一下

 

步驟:

1)   在AndroidManifest.xml中把  <Activity  />標籤  CaptureActivity 的screenOrientation修改為

android:screenOrientation="portrait"


2)  在CameraManager.java類中的getFramingRectInPreview()替換掉原先的 left right top bottom

            //豎屏      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; 


3)  在CameraConfigurationManager.java中void setDesiredCameraParameters(Camera camera)方法

在setParameters之前增加

camera.setDisplayOrientation(90);


4)  在DecodeHandler.java中的 decode(byte[] data, int width, int height)方法在

PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);

之前添加:

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; // Here we are swapping, that‘s the difference to #11  width = height;  height = tmp;  data = rotatedData;


5)  將CameraConfigurationManager的  initFromCameraParameters(Camera camera)方法整個替換如下

該方法防止豎屏後螢幕展開

 

/** * Reads, one time, values from the camera that are needed by the app. */void initFromCameraParameters(Camera camera) {Camera.Parameters parameters = camera.getParameters();previewFormat = parameters.getPreviewFormat();previewFormatString = parameters.get("preview-format");Log.d(TAG, "Default preview format: " + previewFormat + ‘/‘+ previewFormatString);WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);Display display = manager.getDefaultDisplay();screenResolution = new Point(display.getWidth(), display.getHeight());Log.d(TAG, "Screen resolution: " + screenResolution);    Point screenResolutionForCamera = new Point();       screenResolutionForCamera.x = screenResolution.x;       screenResolutionForCamera.y = screenResolution.y;           // preview size is always something like 480*320, other 320*480    if (screenResolution.x < screenResolution.y) {           screenResolutionForCamera.x = screenResolution.y;           screenResolutionForCamera.y = screenResolution.x;    }cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);//cameraResolution = getCameraResolution(parameters, screenResolution);Log.d(TAG, "Camera resolution: " + screenResolution);}


 

至此Zxing 橫屏就切換為豎屏

不足之處請在下方留言  謝謝 

希望對您有用 

資源

http://download.csdn.net/detail/aaawqqq/7278133

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.