My favorites | Sign in
Project Home
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 178: Would like barcode scanning to work in portrait mode
66 people starred this issue and may be notified of changes. Back to list
Status:  WontFix
Owner:  ----
Closed:  Dec 2010


Sign in to add a comment
 
Reported by notavail...@gmail.com, Apr 17, 2009
opening barcode reader always forces rotation to landscape mode, this 
should not be necessary (and is kind of irritating when barcode reader is 
called from other application that is being used in horizontal mode)
Apr 17, 2009
Project Member #1 srowen
Passing to Daniel. The UI seems to work lay out more nicely in landscape, and is more
natural for decoding 1D barcodes (though the viewfinder is currently square anyway).
There are some arguments for it.
Owner: dswitkin
Labels: -Type-Defect Type-Other
Apr 20, 2009
#2 dswit...@gmail.com
I believe it's still not possible to open the camera hardware and begin the preview in portrait mode in the current 
platform. This may change in Cupcake, so we can re-evaluate then.
Summary: Would like barcode scanning to work in portrait mode
Labels: -Type-Other Type-Enhancement
May 8, 2009
#3 twwinw...@gmail.com
Cupcake has now been released, and the screen does the blur effect which occurs when switching from portrait 
view to landscape view in e.g. Browser; is it time to reevaluate the ability to show the app in portrait mode?
Mar 17, 2010
#4 tommyloc...@gmail.com
I'd love to see this as well, it gets to be a real annoyance when you're scanning more 
than one thing turning it back and forth back and forth, or especially when you're 
trying to do it one handed.
Mar 18, 2010
Project Member #5 srowen
Yeah it's not so much that it's technically hard (Shopper does it) it's the UI. We'd be 
pleased to take a patch that defines a reasonable UI when in that mode.
Mar 19, 2010
#6 notavail...@gmail.com
what ui?? there's a scanning box and few buttons, what's wrong with having them in 
portrait just like that?
Mar 19, 2010
Project Member #7 srowen
I don't think it's rocket science, but try fitting those elements in portrait mode, on all 
known screen sizes, in a way that doesn't run off the screen. Remember there are up to 
4 buttons, and consider different translations. We balanced it pretty carefully in the 
horizontal UI. In particular how do you want to stack the contents versus mini-capture 
screen? they can't go side-by-side.

Try it yourself before you dismiss it as easy.
Mar 26, 2010
Project Member #8 srowen
 Issue 362  has been merged into this issue.
Sep 14, 2010
#11 hit....@gmail.com
Uh, guys, I know how to make it scanning in portrait mode.

There are 4 relative files:
1, manifest.xml, you need to make CaptureActivity portrait.

2, DecodeHandler.java, rotate data before buildLuminanceSource, it works becuase in YCbCr_420_SP and YCbCr_422_SP, the Y channel is planar and appears first
---
    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];
    }
---
3, CameraManager.java, getFramingRectInPreview() need to be modified.
---
    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;
---

4, CameraConfigurationManager.java, set camera orientation to portrait in setDesiredCameraParameters() use
---
    parameters.set("orientation", "portrait");
---
and in getCameraResolution(), you need to swap x and y, because camera preview size is something like 480*320, other than 320*480.
---
    int tmp = cameraResolution.x;
    cameraResolution.x = cameraResolution.y;
    cameraResolution.y = tmp;
    return cameraResolution;
---

At least this works on my HTC G2(Android 1.6), more test required.
------------------------------
If you receive more than 1 notice email, that because I commited my comment several times, sorry!
Sep 14, 2010
#12 mernen
See comments #5 to #7. The issue right now is not implementation, but UI design.
Sep 16, 2010
Project Member #13 srowen
Good to know that works. This line may not work on most devices:

parameters.set("orientation", "portrait");

Really you need something like this API call, available in Froyo and later:

camera.setDisplayOrientation(90);

(Not that I've tested it.)

But yes the UI issue remains.
Sep 17, 2010
#14 jirik.ha...@gmail.com
Don't you think that this is right time to reconsider your portrait mode UI? I've seen more buttons on the screen in less space than you have in Barcode Scaner and it was still very useable. Even though I know that some people have quite small screen/resolution, I will be really glad, if you implement this.
Sep 18, 2010
Project Member #15 srowen
How about a patch? I personally don't find it useful since scanning of ("landscape orientation") 1D barcodes is worse. So I am not interested in implementing it. It can surely be done with some cleverness.
Sep 18, 2010
#16 hit....@gmail.com
How about this: just use portrait UI, but keep the red laser unchanged?
portrait.jpg
41.8 KB   View   Download
Sep 18, 2010
Project Member #17 srowen
1D barcodes are wider than tall when upright. In this UI, when upright, the viewfinder is 90 degrees off. No I'm pretty certain it has to be upright too! the box would have to shrink.
Sep 18, 2010
#18 jirik.ha...@gmail.com
The point is that you can make both alternatives (landscape and portrait) possible, so everyony can choose what he want. And clearly there are people who want it work in portrait mode, so why don't let them?
Sep 18, 2010
Project Member #19 srowen
Who's not letting someone submit a patch? I'm not interested in this function myself, but that is not the same as preventing someone from adding it.
Oct 15, 2010
#20 hit....@gmail.com
It seems
parameters.set("orientation", "portrait");
doesn't works on Nexus one.
According to my test, it works on HTC G2 and Sony Ericsson X10i, both of them are android 1.6.

Since
camera.setDisplayOrientation(90);
is introduced in Froyo, and not allowed to be called during preview, I'm gonna stop working on this issue.

Here are some camera parameters of android devices, someone may need them.
CameraParameters.rar
2.7 KB   Download
Oct 15, 2010
#21 fribell
I have a nexus, how to fix it in version 1.6?
I need see scan in portrait mode, thanks for all
Oct 15, 2010
#22 hit....@gmail.com
0, download ZXing-1.6.zip.
1, use code in the attachment.
2, set CaptureActivity's screenOrientation to portrait.
3, organize imports.
4, build and run.


Note that working on G2 and X10i doesn't mean it will work on all 1.6 devices.
related files.rar
8.5 KB   Download
Oct 17, 2010
#23 JB1...@gmail.com
I've taken 20 images and each time it comes up does not recognize the bar code any suggestions?
JB
Oct 17, 2010
#24 hit....@gmail.com
please give me more infomation,
such as android version, sdk version, running device, etc.
Oct 17, 2010
#25 hit....@gmail.com
Sorry, comment 22 has bugs, to make the code run, you need:

1, follow instructions in comment 22;
2, in CameraConfigurationManager.java, line 85, use parameters.set("orientation", "portrait"); (remove "//" in the beginning);
3, modify manifest.xml(copy things you need from zxing's manifest file);
4, build (against android 1.6) and run (on an android 1.6 device)

the attachment is my code, it works on my G2.
BarcodeScannerPortrait.rar
1.6 MB   Download
Oct 24, 2010
#26 fribell
no works on my nexus one :(
Nov 8, 2010
#27 pale.col...@gmail.com
iPhone version works fine in portrait mode... do we care more about that platform?
Nov 15, 2010
#28 heltonte...@gmail.com
Potrait mode would be greate.
Nov 25, 2010
#29 fribell
Someone has found solution to this problem in nexus one?

thanks
Nov 30, 2010
#30 Screamin...@gmail.com
This patch worked on a Samsung Galaxy S... Thanks ;)
Dec 23, 2010
#31 cre...@gmail.com
Patch didn't help on SE x10. Camera finder looks like clockwise turned, and somehow narrowed. Needs proper implementation.

But I definitely sign here for portrait mode!
Dec 23, 2010
#32 dswit...@gmail.com
Sorry folks, this is too much trouble from a compatibility standpoint. We're going to stick with landscape mode only.
Status: WontFix
Jan 25, 2011
#33 ivojansc...@gmail.com
The patch from comment 25 works on a Google Nexus S if you make a small modification. The code that sets the rect in getFramingRectInPreview in CameraManager.java should be:

rect.left = rect.left * cameraResolution.y / surfaceResolution.x;
rect.right = rect.right * cameraResolution.y / surfaceResolution.x;
rect.top = rect.top * cameraResolution.x / surfaceResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / surfaceResolution.y;

(the difference is the use of surfaceResolution instead of screenResolution)
Feb 10, 2011
#34 codeja...@gmail.com
@ srowen


Why not make in an option in the library? And then point the users in the direction on how to fix it?

I REALLY need this app NOT to be turned +90 degrees by default. This is kindda essential in my setup, and the compability problem won't be an issue. 

The app is specificaly designed for 2.1+ devices :)
Feb 10, 2011
Project Member #35 srowen
Barcode Scanner is not a library. You already know what you want to do for your app, so I don't see what bearing it has on this code. This will not be implemented for Barcode Scanner.
Feb 10, 2011
#36 codeja...@gmail.com
I also just encountered line 103 in svn/trunk/javase/src/com/google/zxing/client/j2se/ rotating the image ... Where is this to be found in the Android Source? 
Mar 7, 2011
Project Member #37 srowen
 Issue 736  has been merged into this issue.
Mar 7, 2011
#38 michaelsafyan
I second comment 34. Add an "enable screen rotation" option in settings, but provide this functionality. Furthermore, it is application developers supporting older versions that make handset makers think it is OK to not upgrade their devices; I would argue that it makes a lot of sense to support the latest two versions (Gingerbread and Honeycomb) and ignore older versions.
Mar 7, 2011
#39 michaels...@google.com
FYI, I don't mind so much that the red laser / scanner UI is on its side, but it really bothers me that the result / URL that is presented is on its side. Is there a reason that the result cannot be shown in the correct orientation?
Mar 7, 2011
Project Member #40 srowen
Erm, 99.2% of Android devices are not on Gingerbread/Honeycomb (http://developer.android.com/resources/dashboard/platform-versions.html). I can't see how one would imagine not supporting Froyo. Even dropping 1.5 loses 4% of users, which is nearly a million Barcode Scanners.

I don't think there's a reliable way to get the preview callback to return the image data rotated 90 degrees. The code can do a rotation but it slows things down. Using the short dimension of the display for 1D barcodes is less effective. It requires a second portrait UI too that is not familiar to 20M users out there. (And of course the result UI must be consistent with the scan UI -- can't scan landscape and show results portrait.)

These are reasons not to add this. But more to the point there appears to be nobody who is both in favor of this function and willing to make a patch.
Mar 24, 2011
#42 quattro....@gmail.com
personally, I don't care about portrait or landscape mode, as long as the red line can be turned by 90° (given that the 1D bar-codes are recognized that way too.)


May 5, 2011
#44 Foamy...@gmail.com
The project from comment #25 without any modifications would scan properly on both samsung galaxy tablet, and t mobile g2. But the preview did not appear rotated properly which made impractical to use for me. As mentioned earlier in this thread:

camera.setDisplayOrientation(90);

Is a call that was introduced in froyo. So I rebuilt the project from #25 to API level 2.2 and put in this call instead of:

parameters.set("orientation", "portrait");

This corrected my preview issue and it still scans correctly on both Galaxy Tablet, and G2. Sidenote: I also had to remove "%" from one of the strings inside Strings.xml to get the project to build for me. And lastly when I say that it works correctly now what I mean is scanning via intent and returning the result to an application I am developing. I did not test it as a standalone app but I see no reason why it wouldn't work if you are on a device with recent enough OS version.
May 26, 2011
Project Member #45 srowen
 Issue 844  has been merged into this issue.
Jun 5, 2011
#46 roman.ti...@gmail.com
Comment https://code.google.com/p/zxing/issues/detail?id=178#c11 is very useful. I've got a result only thanks to this guy.

My goal was to run camera in portrait orientation, and to make code reading work at the same time. I'm using zxing 1.6 and building for Android 2.2. Tested on Nexus One.

1. In order to make screen work in portrait, set portrait orientation for the activity (e.g. in manifest) and then config the camera: Use camera.setDisplayOrientation(90) in CameraConfigurationManager.setDesiredCameraParameters(Camera camera). But be aware that: 
- setDisplayOrientation(int) requires Android 2.2 
- setDisplayOrientation(int) does not affect the order of byte array passed in PreviewCallback.onPreviewFrame. (Refer to JavaDoc for additional info)

2. Because preview frames are always in "landscape", we need to rotate them. I used clockwise rotation offered by comment #c11. Do not forget to swap width and height parameters after rotation. DecodeHandler.java, rotate data before buildLuminanceSource in decode(byte[] data, int width, int height)
----------
        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;
----------

3. I also modified CameraManager.java, getFramingRectInPreview(), as recommended by #c11:
---
    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;
---

4. I did not modify getCameraResolution(). That's the second difference to #c11.

As a result, I've got UPC and other 1D codes scanning work in portrait.

P.S. Also you may adjust the size of FramingRect (that's the rectangle visible on the screen during scanning), and FramingRectInPreview will be adjusted automatically.

Jul 6, 2011
#47 nar.kara...@gmail.com
I think that in order to use the scanner in portrait mode there is no need to modify any camera settings.

Launch the camera app in the mobile. You see the exact same picture in the preview as you see in reality - no matter how you tilt or rotate the phone.

The issue with this barcode scanning app is that on portrait orientation of the phone the preview is rotated 90 degrees counter-clockwise and is squeezed vertically.

I believe the camera does NOT feed that preview, but the app does this for some reason.

The portrait mode can be elegantly supported if the app detected the orientation of the phone and, if in portrait orientation, instead of analysing the barcode capture as is, rotate it 90 degrees counter-clockwise then analyse without touching the preview stream.

Please give me an orientation of 
 - which class exactly the barcode analysis happens, and in (DecodeHandler.decode(..) -?)
 - which class the current 90 rotation and vertical squeezing happens
and I'll provide you with a solution that works just fine in any device, any android version without depending on device orientation by
 - removing the original 90 rotation and squeezing
 - putting an orientation handler that modifies a setting 
   which will be used in barcode decoding process
 - within barcode decoding process use the device orientation 
   parameter to decide if the byte array should be rotated before processing.   

No one needs to modify the way the camera works. Just modify the feed from camera as needed.
Aug 3, 2011
#48 martin....@gmail.com
Confirmed https://code.google.com/p/zxing/issues/detail?id=178#c11 solution works on my HTC Desire, Android 2.2 (thanks man). There is one missing line in step 2: data = rotatedData; and you can bypass step 4 and you may need to change parameters.set("orientation", "portrait"); to camera.setDisplayOrientation(90); (the former doesn't work on HTC Desire, tested on 2.1)
I tried it and although it's accurate, the preview image on result handler is blurry as if more than one image are overlapping. 
 
Aug 3, 2011
#49 martin....@gmail.com
The blurry image problem was caused by forgetting to swap data height and width. This solves it https://code.google.com/p/zxing/issues/detail?id=178#c46
 Thanks both of you
Aug 10, 2011
#51 idris.fa...@gmail.com
Dear All , 
My iphone version is also not scanning barcode in portrait mode , don't know which part of objective C code files be modified, 
I am using zxing 1.6 and
"MultiFormatOneDReader" and "QRCodeReader"
as readers array , QRcode works fine , but barcode doesn't ...

Thanks in advance
Aug 10, 2011
#52 ericnewc...@gmail.com
I was able to get portrait scanning to work following steps by #11, #48, #49.

Working on both Nexus One and Huawei U8150 IDEOS. 
Sep 6, 2011
#53 Marek.Urbaniak
I have created a solution which allows reading barcodes in any orientation of a device. You may check it in those apps: 
https://market.android.com/details?id=pl.allegro
https://market.android.com/details?id=pl.ceneo

Barcode Scanner imposes a view layout on top of the camera preview and that is why it would be cumbersome to implement portrait scanning. It would be easier if instead of the camera preview there would be standard background behind buttons and other views. I do not think that the always present camera preview ads any value in the terms of UX.

Additionally, laser box which constrains area taken into consideration when recognizing barcodes, is also not an added value. Indeed, barcodes can be easily recognized outside of this area as well. In Barcode Scanner a user has to first fit barcode into preview and then adjust it within the laser box. Without the laser box it would be easier and faster to read a barcode.
Oct 8, 2011
#54 idris.fa...@gmail.com
Dear All , 


I am an iOS Developer and a user of ZXing Library.

Currently I am working on a project , having a Barcode / QRCode its main feature.

QRCode Scanner is working fine in both orientations (portrait + landscape)

But the problem is with barcode, It works fine in landscape , but can't scan in portrait mode.

I have been googling around for last 6 months for the feature "Scanning barcode in Portrait Mode" using ZXing 1.7 (iPhone).
But I couldn't found any solution.

I also visited the page https://code.google.com/p/zxing/issues/detail?id=178 but couldn't found any solution.

I am using Xcode 3.2.3  , iOS 4.0 and ZXing 1.7

Kindly help me regarding this , 

Oct 16, 2011
Project Member #55 srowen
FWIW this is implemented in Barcode Scanner+ on the Android market (https://market.android.com/details?id=com.srowen.bs.android). It scans in all 4 orientations. It's not easy -- some of the camera plumbing has to be revised pretty significantly. We're going to slowly lay the groundwork with other updates in the open source version now.
Oct 24, 2011
#56 fahad.nasrullah@coeus-solutions.de
C#46 Works fine even with android 2.1. Nice Explanation dude !
Dec 5, 2011
#57 amsi...@gmail.com
I have done changes according to C#46, portrait view works. But it is not scanning QRcodes. App build on 2.2 and tested on 2.3.4. How can i make it scanning wrk in portrait.
Feb 2, 2012
#58 dominik....@gmail.com
I suggest to add a new parameter "portraitMode" to the JavaScript method below in order that the caller can control whether the orientation is portrait or landscape.

Note: Another parameter that I would like to suggest is "torchOn".


BarcodeScanner.prototype.scan = function(torchOn, portraitMode, successCallback, errorCallback) {
    if (errorCallback == null) { errorCallback = function() {}}

    if (typeof errorCallback != "function")  {
        console.log("BarcodeScanner.scan failure: failure parameter not a function");
        return
    }

    if (typeof successCallback != "function") {
        console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
        return
    }

    PhoneGap.exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', [{"torchOn": torchOn, "portraitMode": portraitMode}]);
};


Mar 2, 2012
#59 eduardo....@gmail.com
Hi all,

I've followed the instructions of the comment #46 but no luck with samsung galaxy s 2.

I've recorded the image that it receives after making the rotation in 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; // Here we are swapping, that's the difference to #11
    width = height;
    height = tmp;
    data = rotatedData;


</code>


and a strange thing happens. The image appears to be corrected rotated, but it has like a green filter over it (check file).

Anyone experienced this or have a solution for this?

Thanks.


note:
Code for writing to file:
//this code works great if i pass the byte[] before doing the rotation. 
//After making the rotation the image go to green 
<code>

  public void writeFile(byte[] data, String fileName, int width, int height) throws IOException{
	  FileOutputStream out = new FileOutputStream(fileName);	  	  
	  YuvImage im = new YuvImage(data, ImageFormat.NV21, width,
              height, null);
  		Rect r = new Rect(0,0,width,height);    	
  		im.compressToJpeg(r, 100, out);
  	
	  out.write(data);
	  out.close();
	}

</code>


Thanks again.
 
teste_2.jpg
699 KB   View   Download
Mar 2, 2012
#60 dswit...@gmail.com
Folks, this bug is closed, please stop replying to it.
Mar 20, 2012
#61 onlinedi...@gmail.com
Could this bug be reopened as there are still usecases in which scanning in portrait mode is necessary?

Since a long time, developers are discussing possible solutions to 
enable qr-scanning in portrait mode. 
Nevertheless, solutions as setDisplayOrientation(...) do not work on 
all devices or only allow landscape XOR portrait mode. 

Although I changed a lot of code lines, I could not find a solution to 
build a scanning app which allows scanning in landscape AND portrait 
mode for HTC Desire AND Galaxy Tabs, Android 2.2 (API 8) 

Thanks in advance
Mar 20, 2012
#62 h1bert...@gmail.com
believe it or not I could do run the following comment #34 Flawless.. I
just needed froyo..
May 8, 2012
#63 wnoguchi...@gmail.com
comment #c46, #c11 thanks a lot!!
Jun 19, 2012
#64 sakthimo...@gmail.com
So what is the solution to the problem? c# 60 says, this bug has been closed.

And my one more doubt is: Comments #11 and #46 says, how to make it work in portrait mode. What should i do, if i want to make it work in any angular direction?

Jun 20, 2012
#65 cw...@thisgroup.org
Why was this closed?
What's your rationale for making the community hack a protrait workaround into place?

In the world of inventory management we scan hundreds of items at a time during stocktakes of hundreds of items.

Landscape works well with Tablet devices -- Portrait works best with hand held devices -- so both modes should be supported.

It's a waste of time having to wait for the whole UI to rotate to landscape then I have to change my hand position if the rest of my data entry UI is orientated in portrait.
Jun 20, 2012
#66 h1bert...@gmail.com
Many of us already did this, you could do yourself too, folowing tips
here.. =)
Jun 20, 2012
#67 cw...@thisgroup.org
I came to this forum from the Android store support link -- but maybe I need to vote for a portrait mode for the build that's posted in Google Play? Unless there already is one?
Jun 20, 2012
#68 sakthimo...@gmail.com
I tried the tips given in comment #c46, #c11. the orientation is changed to portrait, but it is not getting scanned as told by another user in c#57. Am using Samsung Ace, Android 2.3
Jun 21, 2012
#69 h1bert...@gmail.com
I did, and it's scanning, have you changed the manifest file?
Jun 21, 2012
#70 sakthimo...@gmail.com
Yes i changed the screenorientation to portrait in manifest file. and followed all the steps given in c#46. Thinking of reverting back to original version (landscape mode) by disclosing this issue under "Known issue(s)"
Jun 21, 2012
#71 h1bert...@gmail.com
I folowed c#11 and 2 of c#46(actually I did
PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, height, width);//replacing here we don't need to swapp width and height)
Jul 6, 2012
#72 ale.parr...@gmail.com
Thank you so much #46 and #11 !
Working nice here.
Jul 19, 2012
#73 schwiz
This should be re-opened, closing it is just plain lazy. 
Aug 16, 2012
#75 senn...@gmail.com
Guys. For make right portrait reader, you should add one line to CameraConfigurationManager.java, in method setDesiredCameraParameters(Camera camera) :

camera.setDisplayOrientation(90);

Thats all!

PS: ofcourse, android:screenOrientation="portrait" in your manifest file. And you should have last library version
Aug 16, 2012
#76 meetindrajeetzite521
camera.setDisplayOrientation(90);

method not working for all the devices who's camera view in portrait mode.
#46 and #11 working fine but camera view looks compress.


Aug 24, 2012
#77 enfi...@gmail.com
I have Android 2.3.6 but the camera preview doesn't work: if i move my phone to right the camera scroll to top.
In Android 2.2 device it's ok.

Can you help me ?

Thank you
Sep 17, 2012
#78 n...@nom.cz

hi, comment - https://code.google.com/p/zxing/issues/detail?id=178#c46 is what I neaded ...but I had problem with "incorrect" scanning ean code because the camera resolution still landscape...
 
here is solution:
I modified CameraConfigurationManager.java -  initFromCameraParameters(Camera camera)
 
1)
//old
//cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, false);
 
//new - alow portrait
cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, true);
 
2)
findBestPreviewSizeValue(parameters, screenResolution, true);
//old
//bestSize = new Point(defaultSize.width, defaultSize.height);
 
//new - swap
bestSize = new Point(defaultSize.height, defaultSize.width);

now portrait mode work perfectly for me
tested - huawei honor
Sep 17, 2012
#80 litbam...@gmail.com
 https://code.google.com/p/zxing/issues/detail?id=178#c46 sometimes incorrect,the big monitor always can't scan the result.here is my solution.

1、modify the CameraConfigurationManager.java -> function findBestPreviewSizeValue

//old.
//newX = Integer.parseInt(previewSize.substring(0, dimPosition));
//newY = Integer.parseInt(previewSize.substring(dimPosition + 1));

//new,i swap it.
newY = Integer.parseInt(previewSize.substring(0, dimPosition));
newX = Integer.parseInt(previewSize.substring(dimPosition + 1));

//in return part.

//old.
//return new Point(bestX, bestY);
//new, i also swap it.
return new Point(bestY, bestX);

that fix all device. if you want to modify the preview area,for example modify it like square.(because i scan the QR_CODE only). you can modify CameraManager.java.

2、 CameraManager.java -> getFramingRect()

      //old...
      int width = screenResolution.x * 3 / 4;
      if (width < MIN_FRAME_WIDTH) {
        width = MIN_FRAME_WIDTH;
      } else if (width > MAX_FRAME_WIDTH) {
        width = MAX_FRAME_WIDTH;
      }
      int height = screenResolution.y * 3 / 4;
      if (height < MIN_FRAME_HEIGHT) {
        height = MIN_FRAME_HEIGHT;
      } else if (height > MAX_FRAME_HEIGHT) {
        height = MAX_FRAME_HEIGHT;
      }
      
      //new.
      int width,height;
      width = height = screenResolution.x * 3 / 4;
      
      if (width < MIN_FRAME_WIDTH) {
          width = height = MIN_FRAME_WIDTH;
      } else if (width > MAX_FRAME_WIDTH) {
         width = height = MAX_FRAME_WIDTH;
      }  
Oct 28, 2012
#81 stein.de...@lin-k.net
Indeed, findBestPreviewSizeValue in CameraConfigurationManager needs to be modified as well, in addition to #11 and #46. This fixes slow or erroneous EAN scanning.
I replaced:
   boolean isCandidatePortrait = realWidth < realHeight;
with:            
boolean isCandidatePortrait = realWidth < realHeight ^ screenResolution.x < screenResolution.y;

This is somewhat of a quick fix and probably should be investigated more thoroughly 
Oct 29, 2012
#82 martin.n...@gmail.com
Hey Guys if i try Comment 11 and 46 i got an Error in the PlanarYUVLuminanceSource.java on line 47

 if (left + width > dataWidth || top + height > dataHeight) { 
            throw new IllegalArgumentException("Crop rectangle does not fit within image data."); }

How can i fix this?
Nov 5, 2012
#83 aprsdr...@googlemail.com
I have tried to create a proper patch file from all the hints above, it is a .diff against zxing 2.0, please do not shoot me for the code quality :)
0001-Make-zxing-work-in-portrait-mode.patch
9.2 KB   View   Download
Nov 6, 2012
#84 chacke...@gmail.com
Hi Guys,

I have successfully been able to rotate the image to portrait, but with a few small issues.

When in portrait the image is kinda squashed horizontally and when in landscape orientation it is stretched horizontally.

Any ideas on what causes this and where I should start looking for a place to fix it?

Thanks in advance,
Conor
Nov 23, 2012
#86 madeinus...@gmail.com
The same question as #84, if anyone knows solution help please.
Nov 23, 2012
#87 h1bert...@gmail.com
Lock it when scaning..
Dec 17, 2012
#88 robert.l...@gmail.com
I have this strange issue on a Xperia GO, ICS. Only half of the screen is visible. So the left half of the screen is black and the rest is showing the picture starting from the left side. So that I get something like 160x480 black, then 160x480 with the actual picture. The laser and box and yellow dots are painted correctly. I can't understand why this is happening.

Same code works great under 2.3.x on the same device <3 
Dec 21, 2012
#90 somayaji...@gmail.com
This https://github.com/pplante/zxing-android  works fine in portrait mode!  it's more faster..! but it's not working on Nexus 7, Shows dialog " Sorry the android camera encounters a problem, you may needs to restart the device ! (device without rear camera! getting this error)
Dec 30, 2012
#91 zhong871...@gmail.com
@comment 84 86
the 'aspect' ratio of camera previewsize must the same as surface view 's.  In CameraConfigurationManager that is the variable 'cameraResolution'( see the function setDesiredCameraParameters 'parameters.setpreviewsize'),  so here is the solution

1) get camera resolution from CameraManager.java 
public point getCameraResolution
{
      return configManager.getCameraResolution();
}

2) in CaptureActivity.java replace the surfaceChanged method

public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
    Point p = cameraManager.getCameraResolution();
    float ration = (float)p.y / p.x;
    if(width < height)//portrait height / width
    {
         width = (int) (height * ration)
    }
    else//landscape  width / height
    {
         height = (int) (width * ration)
    }

    android.widget.FrameLayout.LayoutParams params = new android.widget.FrameLayout.LayoutParams(width, height);
    surfaceView.setLayoutParams(params);
}

then that will work


Jan 4, 2013
#92 losdl...@gmail.com
@91

While it seems to work, the detection overlay gets screwed up: The edge highlights no longer matches the camera, and when the code is found, the snapshot shown is still in the wrong aspect.
Jan 16, 2013
#93 digicash...@gmail.com
Hi,
I followed your solutions but I still have a problem on some devices. It seems the instruction "camera.setDisplayOrientation (90)" is not recognize by Galaxy Ace and Galaxy Y. 

I tried other way to rotate the camera but didn't work at all.
Any idea?
Feb 7, 2013
#94 p...@sedlacek.biz
I have patched the latest version of Barcode Reader (4.3.1) using #84, #81, #75 (thanks a lot, guys!) and created a proper patch. 
It seems to work very well, I'm so glad I can finally run Barcode Reader in portrait! I find portrait scanning much easier, especially one-handed, I don't have to rotate the phone in my hand, just run and scan.

It's a pity the developer doesn't find the portrait mode beneficial. On larger screens/resolutions there doesn't seem to be any problem with the portrait layout.
I personally would greatly appreciate portrait mode if it did away with all the buttons as I'm mainly using Barcode Reader as a reader for other applications (the excellent WiFi Barcode Reader or Movielicious).

Patch attached. I would appreciate any comments and testing.
zxing-barcode-reader-4.3.1-portrait.patch
8.7 KB   View   Download
Feb 7, 2013
#95 p...@sedlacek.biz
Oops, Barcode Scanner (not Reader), of course! Sorry for that.
Feb 12, 2013
#96 vbW...@gmail.com
Works very fine. Thanks a lot.
Feb 12, 2013
#97 jtot...@gmail.com
Thanks for the patch in #94, it works great on my Galaxy S3 (haven't tested yet over a wider range of devices.)

Has anyone enhanced this so that it can support either landscape or portrait mode? Specifically, if the device is in landscape mode when launching the  CaptureActivity then it will lock it in landscape mode, and if starting in portrait mode then it'd lock it in portrait mode. This would allow for phones to display in portrait mode and tablets to display in landscape mode.
Feb 12, 2013
#98 jtot...@gmail.com
I was able to modify the patch to support both landscape and portrait modes. Here are the steps for others who want to do the same:

1. In AndroidManifest.xml, change the supported orientation to sensor:

<activity android:name="com.google.zxing.client.android.CaptureActivity"
                          android:screenOrientation="sensor"
                          android:clearTaskOnLaunch="true"
                          android:stateNotNeeded="true"
                          android:configChanges="orientation|keyboardHidden"
                          android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                          android:windowSoftInputMode="stateAlwaysHidden">

2. At the end of CaptureActivity.java - onCreate, disable orientation changes:

//disable orientation changes.
		boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
		setRequestedOrientation(isLandscape ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

3. Everywhere that you made changes to support portrait mode from the patch in #94, make the logic handle landscape mode too:

if(this.context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
//do the patch logic for portrait mode
}
else {
//do the original logic for landscape mode that the patch commented out
}

Basically this will launch the activity in the device's current orientation (landscape or portrait) and then it will lock it to that orientation, which is a lot better than hard-coding it to either landscape or portrait.
Feb 13, 2013
#99 daniel.o...@silvercar.com
I just want to say comment #94 was the one that sealed the deal. Everything works perfect in portrait now. Just take the latest core.java from ZXing, and the latest 4.31 BarcodeScanner implementation, apply the patch to the 4.31 code and you're good to go.

patch -p1 < ./zxing-barcode-reader-4.3.1-portrait.patch 
patching file android/AndroidManifest.xml
Hunk #2 succeeded at 51 with fuzz 2 (offset -7 lines).
patching file android/src/com/google/zxing/client/android/DecodeHandler.java
Hunk #2 FAILED at 106.
Hunk #3 FAILED at 123.
2 out of 3 hunks FAILED -- saving rejects to file android/src/com/google/zxing/client/android/DecodeHandler.java.rej
patching file android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
Hunk #3 succeeded at 222 (offset -6 lines).
Hunk #4 succeeded at 232 (offset -6 lines).
patching file android/src/com/google/zxing/client/android/camera/CameraManager.java
Hunk #3 succeeded at 211 (offset -2 lines).
Hunk #4 succeeded at 250 (offset -2 lines).
Hunk #5 succeeded at 313 (offset -2 lines).
patching file android/src/com/google/zxing/client/android/ViewfinderView.java

Ignore the failures and delete the .orig and .rej files and you're good to go. 
Feb 13, 2013
#100 p...@sedlacek.biz
#98 jtot, thanks for the pointers! I don't know nearly anything about Android programming. I will try to incorporate your changes to my patch.

#99 @daniel.o, thanks for the comment. It's strange that the patch doesn't apply cleanly; did you apply it against latest git version or 4.31 release source?
Feb 20, 2013
#101 sergey.g...@gmail.com
Nope. Patch attached to #94 doesn't work with 4.3.1.
It doest not apply proper preview rotation in portrait (tested on Galaxy Pocket and android emulator) 
Feb 20, 2013
#102 dswit...@gmail.com
(No comment was entered for this change.)
Owner: ---
Mar 12, 2013
#103 shidhi.s...@gmail.com
Thanks......

May 6, 2013
#104 bangoj...@gmail.com
The same problem as #84... I tested in Xperia U and 75% of the screen is black... It seems the camera moves to the right, out of the screen. Almost all other device work fine. Does anyone know how can I solve it? 
Thank you.
May 14, 2013
#105 sdau...@gmail.com
The same problem as #84.I'm a newer. Who can offer a  good method?Thank you!!!
May 14, 2013
#106 ironst...@gmail.com
I'm attaching my patch here...  It implements all the other patches above and results in portrait scanning.

I kept all the old landscape code in there.    My original idea was to detect orientation at start-up and keep that orientation until close...   Right now however it's hard coded to portrait.

Perhaps its useful, perhaps I'll finish it later, but if anyone else wants to mess with it its here.   For right now portrait only fills my requirement and I haven't got time to work on it.

zxing-barcode-reader-4.3.1-portrait_and_incomplete-dynamic-2013-04-11.patch
9.9 KB   View   Download
May 20, 2013
#107 th3positivementaloctopus
Hello!

I've downloaded the zxing-master.zip from https://github.com/zxing/zxing and I've used your patch as well.
I've 2 problems (tested in various devices as HTC One, Nexus 7, Galaxy Mini... same behaviour):

- Problem 1, I had to add this line in CameraManager getFramingRectInPreview():
setFramingViewSize(new Point(MAX_FRAME_WIDTH_PORTRAIT, MAX_FRAME_HEIGHT_PORTRAIT + 100));

before:

rect.left = rect.left * cameraResolution.y / framingViewSize.x;
rect.right = rect.right * cameraResolution.y / framingViewSize.x;
rect.top = rect.top * cameraResolution.x / framingViewSize.y;
rect.bottom = rect.bottom * cameraResolution.x / framingViewSize.y;

otherwise it would throw null pointer exception (framingViewSize null).

- Problem 2, won't detected in portrait mode. Landscape does it marvellously.


What am I doing wrong here?
Thanks for your time.

May 20, 2013
#109 th3positivementaloctopus
Problem 2 it's "kinda solved", I just had to play with that line (the one I had to add) values.

As I've stated above if I didn't add it it would throw null point for framingViewSize

I didn't went through zxing code, I'll do it tomorrow, but if you could help me understand why I had to add this line it would be great. It shouldn't be necessary right?

Take care.
May 21, 2013
#110 th3positivementaloctopus
setFramingViewSize(new Point(framingRect.centerX() * 2, framingRect.centerY() * 2));

tested on different devices and it's working. Don't no if it's the best solution, but it's working.
Jun 2, 2013
#112 dubbels...@gmail.com
In order to implement the intention in #106 "My original idea was to detect orientation at start-up and keep that orientation until close."

I removed the call to the showHelpOnFirstLaunch-.method in last row of the onCreate-method in CaptureActivity. I moved the code from the onResume method to the end of the onCreate-method. As the last step I inserted the below rows in the very end of the onCreate method 


    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
Jun 4, 2013
#114 h1bert...@gmail.com
Scanning in portrait mode work.
I did.
Jun 28, 2013
#115 jrrz.ie...@gmail.com
Patch on comment #94 (zxing-barcode-reader-4.3.1-portrait.patch) worked perfectly on Nexus 4. Thanks a lot :)

Oct 3, 2013
#116 murugang...@gmail.com
Hi am new to using zxing qr code reader. 
I did qr code scanning, by downloading zxing 2.2 zip and get source from android folder package and core folder package and change R file package name in come class. Finally got it. its working in landscape mode. But i need Portrait mode. so i did changes in zxing-barcode-reader-4.3.1-portrait.patch (8.7 KB). after that i got portrait mode but when i scan it shows X axis and Y axis get interchanged in Samsung Galaxy y android version 2.3.6 but i run the same thing i got success result in later version 4.1  

But i need how to get correct Orientation in Samsung Galaxy y android version 2.3.6. Please any one help me...

Thanks
Jan 3, 2014
#117 lucasjot...@gmail.com
Same problem as c#93 and c#116, camera image stays flipped 90 degrees on Galaxy Y... probably it has something to do with ldpi-screen devices?  solutions commented above works great on Galaxy S2 Lite (GT-I9070). Both phones with android 2.3.6...
Jan 3, 2014
#118 lucasjot...@gmail.com
In addition to the last comment, Galaxy Y still can scan qrcodes properly, and the opaque result bitmap is drawn correctly (ie, in portrait orientation)
Feb 20, 2014
#119 vipinran...@gmail.com
thanks for the patch in #94.working fine on my galaxy s advance
May 25, 2014
#120 hugehard...@gmail.com
Is there any solution for ldip? It does not work in ldip, others are ok.
Yesterday (28 hours ago)
#121 bayro...@gmail.com
How to switch the camera to portrait mode in version 3.1.0 of the ZXing?
Sign in to add a comment

Powered by Google Project Hosting