• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps [RESOLVED] ZXing Barcode scanner - Pixelated view using Java (on some devices)

OANSI

Lurker
***FOR THE SOLUTION SEE MY LAST RESPONSE TO THIS THREAD***

I'm in the process of trying to replicate an app I made using Kotlin, but moving it over to Java. I have pasted the code for the creation of both ZXing scanner views on both apps. The pro

In Kotlin the code works perfect and you get a nice crisp camera view (same quality as the camera) however on Java it is incredibly low resolution, and I can't figure out why.

Any advice would be much appreciated.

Both versions are using ZXing 1.9.8.

I have put the screenshots/code in spoilers as to not make this post huge.

tZmFUDQ.png
UFvw2IQ.png

Java:
public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {

    private static final int REQUEST_CAMERA =1;
    private ZXingScannerView scannerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        scannerView = new ZXingScannerView(this);
        setContentView(scannerView);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            if(checkPermission()){
                Toast.makeText(MainActivity.this, "Permission is granted", Toast.LENGTH_LONG).show();

            }else{
                requestPermission();
            }
        }

    }

Code:
class MainActivity : AppCompatActivity(),ResultHandler{
    private var REQUES_CAMERA = 1
    private var scannerView : ZXingScannerView?=null

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        scannerView= findViewById(R.id.scanner)
      
        //Checking permissions
        if(!checkPermission()){
            requestPermissions()
        }
  
        setupScanner()

    }

    private fun setupScanner() {
            scannerView?.startCamera()
            scannerView?.visibility = View.VISIBLE
            (scannerView?.layoutParams as LinearLayout.LayoutParams).weight = 1f;
            try {
                // val num = parseDouble(txtInput?.text?.toString().substring(2,2))
            } catch (e: NumberFormatException) {
                //numeric = false
            }
    }

    private fun checkPermission() : Boolean{
        return         ContextCompat.checkSelfPermission(this@MainActivity, android.Manifest.permission.CAMERA) ==PackageManager.PERMISSION_GRANTED
        }
 
Last edited:
I have just edited the title as I have found an even stranger part to this whole debacle.

I have been testing on a P8 lite - but I've just redeployed the app to a Y6 2019 and it's absolutely fine on here...

LSUmOS1.png


Y6 2019 - 9.1.0
P8 Lite - 5.0.1

I try to update the P8 but it says "No updates available"
 
Last edited:
UPDATE - I have found the solution to the problem, it appears to be the AspectTolerance.

By default it appears to be set to 0.1f

In my case, I was able to fix it using
scannerView.setAspectTolerance(0.2f);

Worth checking different values if 0.2f doesnt work for you.
 
Last edited:
Back
Top Bottom