Comments (22)
I also had this issue (camera screen is zoomed). I solved this problem just added full screen mode in onCreate method:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
from barcode-reader.
Hello. it's seem still not fix in new version gradle.
from barcode-reader.
@prathibhaprabs: Get the source code you can custom and fix that issue. At CameraSourcePreview.java -> protected void onLayout (boolean changed, int left, int top, int right, int bottom).
I fixed for my project like below:
@OverRide
protected void onLayout (boolean changed, int left, int top, int right, int bottom)
{
int width = getWidth();
int height = getHeight();
// if (mCameraSource != null) {
// Size size = mCameraSource.getPreviewSize();
// if (size != null) {
// width = size.getWidth();
// height = size.getHeight();
// }
// }
//
// int layoutWidth = right - left;
// int layoutHeight = bottom - top;
//
// // Swap width and height sizes when in portrait, since it will be rotated 90 degrees
// if (isPortraitMode()) {
// int tmp = width;
// //noinspection SuspiciousNameCombination
// width = height;
// height = tmp;
// }
//
// int childWidth = layoutWidth;
// int childHeight = (int) (((float) layoutWidth / (float) width) * height);
//
// if (isPortraitMode()) {
// childHeight = layoutHeight;
// childWidth = (int) (((float) layoutHeight / (float) height) * width);
// }
for (int i = 0; i < getChildCount(); ++i) {
getChildAt(i).layout(0, 0, width, height);
}
try {
startIfReady();
} catch (SecurityException se) {
Log.e(TAG, "Do not have permission to start the camera", se);
} catch (IOException e) {
Log.e(TAG, "Could not start camera source.", e);
}
}
from barcode-reader.
Listed solution is not correct. It will break aspect ratio.
The problem here is that onLayout()
of CameraSourcePreview
is called before CameraSource#mPreviewSize
is updated to proper value. By default mPreviewSize
holds initial values (1024x768) or those set in CameraSource.Builder#setRequestedPreviewSize(int, int)
. So that is the cause of initial deformation.
This must be fixed by forcing onLayout()
once mPreviewSize
is correct. Quick fix is adding
requestLayout()
to CameraSourcePreview#startIfReady()
.
private void startIfReady() throws IOException, SecurityException {
if (mStartRequested && mSurfaceAvailable) {
mCameraSource.start(mSurfaceView.getHolder());
if (mOverlay != null) {
Size size = mCameraSource.getPreviewSize();
int min = Math.min(size.getWidth(), size.getHeight());
int max = Math.max(size.getWidth(), size.getHeight());
if (isPortraitMode()) {
// Swap width and height sizes when in portrait, since it will be rotated by
// 90 degrees
mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
} else {
mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
}
mOverlay.clear();
requestLayout();
}
mStartRequested = false;
}
}
from barcode-reader.
@mroczis i've tried your fix..but i'm having a green stripe on the right side of the screen
from barcode-reader.
I found a solution that solve the issue on my side:
- first, on CameraSourcePreview#startIfReady() , move the requestLayout() juste before the last '}'
- second, modify the CameraSourcePreview#onLayout() to adjust/center the view
@Override
protected void onLayout (boolean changed, int left, int top, int right, int bottom)
{
int width = getWidth();
int height = getHeight();
if (mCameraSource != null) {
Size size = mCameraSource.getPreviewSize();
if (size != null) {
width = size.getWidth();
height = size.getHeight();
// Swap width and height sizes when in portrait, since it will be rotated 90 degrees
if (isPortraitMode()) {
int tmp = width;
//noinspection SuspiciousNameCombination
width = height;
height = tmp;
}
}
}
int layoutWidth = right - left;
int layoutHeight = bottom - top;
// int childWidth = layoutWidth;
// int childHeight = (int) (((float) layoutWidth / (float) width) * height);
//
// if (isPortraitMode()) {
// childHeight = layoutHeight;
// childWidth = (int) (((float) layoutHeight / (float) height) * width);
// }
float ratio = ((float)Math.max(layoutHeight, layoutWidth))/(float)Math.min(width, height);
int childWidth = (int) ((float) width * ratio);
int childHeight = (int) ((float) height * ratio);
int childLeft = (childWidth>layoutWidth)?(childWidth-layoutWidth)/-2:0;
int childTop = (childHeight>layoutHeight)?(childHeight-layoutHeight)/-2:0;
for (int i = 0; i < getChildCount(); ++i) {
getChildAt(i).layout(childLeft, childTop, childWidth, childHeight);
}
try {
startIfReady();
} catch (SecurityException se) {
Log.e(TAG, "Do not have permission to start the camera", se);
} catch (IOException e) {
Log.e(TAG, "Could not start camera source.", e);
}
}
I hope this will solve the issue for you too ;)
from barcode-reader.
In my case the green line only shows if i don't use Full Screen, Below is what i did to fix it.
Hope it helps others.
In Android Manifest.
<activity android:name=".ScannerActivity"
android:theme="@style/FullTheme"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.Scanner" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Style used.
<style name="FullTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Activity's OnCreate
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
/* use as full screen */
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
setContentView(R.layout.activity_scanner)
/* hide keyboard if necessary */
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(relativeScanner.windowToken, 0)
//# Initialize and show barcode fragment
mBarcodeReader = supportFragmentManager.findFragmentById(R.id.barcode_fragment) as BarcodeReader
}
from barcode-reader.
Is the issue still exists?
from barcode-reader.
yes @ravi8x
from barcode-reader.
I'm also getting the same issue.
from barcode-reader.
I'm facing the same issue. For me it happens right after allowing the application to take picture and record video (granting permission). If the app already got the permission (re-launching the activity) it just works fine
from barcode-reader.
@ravi8x, do you think the fix proposed by @hoang08t2 can be accepted and reported to main code in a new version ? Thanks.
Can you add a way to set autofocus 'on' from code, actually this can be done only if you define it in xml.
Thanks for all.
from barcode-reader.
@Llorc currently, The problem will come when you use a device with high density so that's my solution to fix that issue. I hope @ravi8x will upgrade to a new version.
from barcode-reader.
@Llorc your solution did not work for me.
At first, it seemed fine when I tried, but if you put the app to background and then come back, a black stripe appears on the right.
from barcode-reader.
Hi @Llorc ,
Your solution works but I can't get it scanned. The scan functionality was somehow didn't went through the scanning process.
Nothing happens when I tried scanning the barcode/qrcode. Are you experiencing the same? How can I get the scanning works? I'm running it on Amazon KF tablet 5th generation.
Any help would be greatly appreciated. Thank you!
Cheers,
Christian
from barcode-reader.
Also experiencing a green bar on the scanner, using this library on a custom app on the following device : https://fr.aliexpress.com/item/IPDA020-Tablet-pos-terminal-Android5-1-System-Wirelss-portable-bluetooth-58mm-thermal-printer-PDA-Sunmi-V1/32827863258.html?spm=a2g0s.9042311.0.0.AHhM7K
from barcode-reader.
I'm also experiencing the same problem (a green bar appears on right of the scanner ). Did somebody find the fix for that?
from barcode-reader.
hello @mmarshad . Let download this project and add to your Android Studio as library, then modify the class CameraSourcePreview as above comment
from barcode-reader.
As I am adding the barcode scanner from a fragment, setting full-size will not work for me. Why does it take so long to fix this ?
from barcode-reader.
Any ideas about this issue?. I am trying fix this but when I apply style full Theme the Qrs are detected in the right side not in the center. Any solution?
Thansk
from barcode-reader.
This solve my problem by setting the screen to full screen
from barcode-reader.
What still not fixed this issue ??
from barcode-reader.
Related Issues (20)
- switch to front camera HOT 2
- Layout info.androidhive.barcode.BarcodeReader
- Can I set a border for the square area? HOT 2
- Camera is distorted & no result HOT 1
- Limiting the types of barcodes that can be read
- Green color in right side of camera preview HOT 4
- How to turn on flash manually (using code not XML) ? HOT 1
- Class Cast Exception
- Camera is scanning qr not only in the center but also on the right left ... HOT 2
- First time install - long wait for download of QR Core libraries
- Duplicate class android.support.design.widget.CoordinatorLayout found HOT 1
- Change position of barcode scanner and borders on top left, top right, bottom left, and bottom right.
- Manual Flashlight
- Green color in right side of camera preview HOT 5
- Google Vision Api Camera preview issue HOT 1
- Hi Ravi Tamada
- java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference HOT 8
- Camera 1 API is deprecated,
- Migration to MavenCentral HOT 1
- Android 11 device
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from barcode-reader.