My favorites | Sign in
Project Home
New issue   Search
  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, 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
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
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
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
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
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,, 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,, getFramingRectInPreview() need to be modified.
    rect.left = rect.left * cameraResolution.y / screenResolution.x;
    rect.right = rect.right * cameraResolution.y / screenResolution.x; = * cameraResolution.x / screenResolution.y;
    rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;

4,, 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:


(Not that I've tested it.)

But yes the UI issue remains.
Sep 17, 2010
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
How about this: just use portrait UI, but keep the red laser unchanged?
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
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
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.

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.
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
0, download
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
I've taken 20 images and each time it comes up does not recognize the bar code any suggestions?
Oct 17, 2010
please give me more infomation,
such as android version, sdk version, running device, etc.
Oct 17, 2010
Sorry, comment 22 has bugs, to make the code run, you need:

1, follow instructions in comment 22;
2, in, 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.
1.6 MB   Download
Oct 24, 2010
#26 fribell
no works on my nexus one :(
Nov 8, 2010
iPhone version works fine in portrait mode... do we care more about that platform?
Nov 15, 2010
Potrait mode would be greate.
Nov 25, 2010
#29 fribell
Someone has found solution to this problem in nexus one?

Nov 30, 2010
This patch worked on a Samsung Galaxy S... Thanks ;)
Dec 23, 2010
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
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
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 should be:

rect.left = rect.left * cameraResolution.y / surfaceResolution.x;
rect.right = rect.right * cameraResolution.y / surfaceResolution.x; = * 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
@ 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
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
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 ( 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
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
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:


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
Comment 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., 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, getFramingRectInPreview(), as recommended by #c11:
    rect.left = rect.left * cameraResolution.y / screenResolution.x;
    rect.right = rect.right * cameraResolution.y / screenResolution.x; = * 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
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
Confirmed 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
The blurry image problem was caused by forgetting to swap data height and width. This solves it
 Thanks both of you
Aug 10, 2011
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
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:

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
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 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 ( 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
C#46 Works fine even with android 2.1. Nice Explanation dude !
Dec 5, 2011
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
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");

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

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

Mar 2, 2012
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


    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;


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?


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 

  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);


Thanks again.
699 KB   View   Download
Mar 2, 2012
Folks, this bug is closed, please stop replying to it.
Mar 20, 2012
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
believe it or not I could do run the following comment #34 Flawless.. I
just needed froyo..
May 8, 2012
comment #c46, #c11 thanks a lot!!
Jun 19, 2012
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
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
Many of us already did this, you could do yourself too, folowing tips
here.. =)
Jun 20, 2012
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
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
I did, and it's scanning, have you changed the manifest file?
Jun 21, 2012
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
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
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
Guys. For make right portrait reader, you should add one line to, in method setDesiredCameraParameters(Camera camera) :


Thats all!

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

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

hi, comment - is what I neaded ...but I had problem with "incorrect" scanning ean code because the camera resolution still landscape...
here is solution:
I modified -  initFromCameraParameters(Camera camera)
//cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, false);
//new - alow portrait
cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, true);
findBestPreviewSizeValue(parameters, screenResolution, true);
//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 sometimes incorrect,the big monitor always can't scan the is my solution.

1、modify the -> function findBestPreviewSizeValue

//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.

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

2、 -> getFramingRect()

      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;
      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
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;
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
Hey Guys if i try Comment 11 and 46 i got an Error in the 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
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 :)
9.2 KB   View   Download
Nov 6, 2012
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,
Nov 23, 2012
The same question as #84, if anyone knows solution help please.
Nov 23, 2012
Lock it when scaning..
Dec 17, 2012
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
This  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
@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 
public point getCameraResolution
      return configManager.getCameraResolution();

2) in 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);

then that will work

Jan 4, 2013

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
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
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.
8.7 KB   View   Download
Feb 7, 2013
Oops, Barcode Scanner (not Reader), of course! Sorry for that.
Feb 12, 2013
Works very fine. Thanks a lot.
Feb 12, 2013
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
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=""

2. At the end of - 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
I just want to say comment #94 was the one that sealed the deal. Everything works perfect in portrait now. Just take the latest 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/
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/
patching file android/src/com/google/zxing/client/android/camera/
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/
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/

Ignore the failures and delete the .orig and .rej files and you're good to go. 
Feb 13, 2013
#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
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
(No comment was entered for this change.)
Owner: ---
Mar 12, 2013

May 6, 2013
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
The same problem as #84.I'm a newer. Who can offer a  good method?Thank you!!!
May 14, 2013
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.

9.9 KB   View   Download
May 20, 2013
#107 th3positivementaloctopus

I've downloaded the from 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():


rect.left = rect.left * cameraResolution.y / framingViewSize.x;
rect.right = rect.right * cameraResolution.y / framingViewSize.x; = * 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
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) {
    } else {
Jun 4, 2013
Scanning in portrait mode work.
I did.
Jun 28, 2013
Patch on comment #94 (zxing-barcode-reader-4.3.1-portrait.patch) worked perfectly on Nexus 4. Thanks a lot :)

Oct 3, 2013
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...

Jan 3, 2014
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
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
thanks for the patch in #94.working fine on my galaxy s advance
May 25, 2014
Is there any solution for ldip? It does not work in ldip, others are ok.
Yesterday (28 hours ago)
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