Code Monkey home page Code Monkey logo

Comments (22)

AlekseyDanilov avatar AlekseyDanilov commented on June 2, 2024 7

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.

fukemy avatar fukemy commented on June 2, 2024 4

Hello. it's seem still not fix in new version gradle.

from barcode-reader.

hoang08t2 avatar hoang08t2 commented on June 2, 2024 3

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

mroczis avatar mroczis commented on June 2, 2024 1

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.

shankhajana avatar shankhajana commented on June 2, 2024 1

@mroczis i've tried your fix..but i'm having a green stripe on the right side of the screen
screenshot_2018-01-06-17-53-13

from barcode-reader.

Llorc avatar Llorc commented on June 2, 2024 1

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.

johnguild avatar johnguild commented on June 2, 2024 1

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.

ravi8x avatar ravi8x commented on June 2, 2024

Is the issue still exists?

from barcode-reader.

prathibhaprabs avatar prathibhaprabs commented on June 2, 2024

yes @ravi8x

from barcode-reader.

AnujProject avatar AnujProject commented on June 2, 2024

I'm also getting the same issue.

from barcode-reader.

pesutsoos avatar pesutsoos commented on June 2, 2024

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.

Llorc avatar Llorc commented on June 2, 2024

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

hoang08t2 avatar hoang08t2 commented on June 2, 2024

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

alanpaivaa avatar alanpaivaa commented on June 2, 2024

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

ccsavvy avatar ccsavvy commented on June 2, 2024

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.

Renrhaf avatar Renrhaf commented on June 2, 2024

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.

mmarshad avatar mmarshad commented on June 2, 2024

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.

fukemy avatar fukemy commented on June 2, 2024

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.

1amGr00t avatar 1amGr00t commented on June 2, 2024

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.

moisesvs avatar moisesvs commented on June 2, 2024

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.

originalkwame avatar originalkwame commented on June 2, 2024

This solve my problem by setting the screen to full screen

from barcode-reader.

sanjeet007 avatar sanjeet007 commented on June 2, 2024

What still not fixed this issue ??

from barcode-reader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.