1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by OANSI, Oct 16, 2019.

  1. OANSI

    OANSI Lurker
    Thread Starter

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

    [​IMG]
    [​IMG]

    Code (Java):
    1. public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
    2.  
    3.     private static final int REQUEST_CAMERA =1;
    4.     private ZXingScannerView scannerView;
    5.  
    6.  
    7.     @Override
    8.     protected void onCreate(Bundle savedInstanceState) {
    9.         super.onCreate(savedInstanceState);
    10.         setContentView(R.layout.activity_main);
    11.  
    12.         scannerView = new ZXingScannerView(this);
    13.         setContentView(scannerView);
    14.         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
    15.             if(checkPermission()){
    16.                 Toast.makeText(MainActivity.this, "Permission is granted", Toast.LENGTH_LONG).show();
    17.  
    18.             }else{
    19.                 requestPermission();
    20.             }
    21.         }
    22.  
    23.     }
    24.  

    Code (Text):
    1. class MainActivity : AppCompatActivity(),ResultHandler{
    2.     private var REQUES_CAMERA = 1
    3.     private var scannerView : ZXingScannerView?=null
    4.  
    5.     override fun onCreate(savedInstanceState: Bundle?) {
    6.  
    7.         super.onCreate(savedInstanceState)
    8.         setContentView(R.layout.activity_main)
    9.         scannerView= findViewById(R.id.scanner)
    10.      
    11.         //Checking permissions
    12.         if(!checkPermission()){
    13.             requestPermissions()
    14.         }
    15.  
    16.         setupScanner()
    17.  
    18.     }
    19.  
    20.     private fun setupScanner() {
    21.             scannerView?.startCamera()
    22.             scannerView?.visibility = View.VISIBLE
    23.             (scannerView?.layoutParams as LinearLayout.LayoutParams).weight = 1f;
    24.             try {
    25.                 // val num = parseDouble(txtInput?.text?.toString().substring(2,2))
    26.             } catch (e: NumberFormatException) {
    27.                 //numeric = false
    28.             }
    29.     }
    30.  
    31.     private fun checkPermission() : Boolean{
    32.         return         ContextCompat.checkSelfPermission(this@MainActivity, android.Manifest.permission.CAMERA) ==PackageManager.PERMISSION_GRANTED
    33.         }
    34.  
     


    #1 OANSI, Oct 16, 2019
    Last edited: Oct 18, 2019
  2. OANSI

    OANSI Lurker
    Thread Starter

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

    [​IMG]


    Y6 2019 - 9.1.0
    P8 Lite - 5.0.1

    I try to update the P8 but it says "No updates available"
     
    #2 OANSI, Oct 17, 2019
    Last edited: Oct 17, 2019
  3. OANSI

    OANSI Lurker
    Thread Starter

    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.
     
    #3 OANSI, Oct 18, 2019
    Last edited: Oct 18, 2019
Loading...
Similar Threads - RESOLVED ZXing Barcode
  1. Elereth
    Replies:
    0
    Views:
    976
  2. Morganw236
    Replies:
    3
    Views:
    688
  3. Advait
    Replies:
    13
    Views:
    780
  4. notableuser
    Replies:
    0
    Views:
    372
  5. Advait
    Replies:
    33
    Views:
    1,261
  6. Advait
    Replies:
    5
    Views:
    500
  7. Jibin John
    Replies:
    0
    Views:
    838
  8. makoa2
    Replies:
    0
    Views:
    465
  9. Roger Kamal
    Replies:
    0
    Views:
    1,036
  10. Advait
    Replies:
    4
    Views:
    2,897

Share This Page

Loading...