Comments (8)
Have you checked out the sample app? Does the issue occur in the sample app too?
Can you create a simple implementation reproducing the issue for me to debug?
Thank you
from qreader.
My code is the same as the demo, I enter the code below:
`package eu.followine.followine;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.design.widget.NavigationView;
import android.support.v4.app.ActivityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageButton;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import cz.msebera.android.httpclient.Header;
import github.nisrulz.qreader.QRDataListener;
import github.nisrulz.qreader.QREader;
public class Main extends AppCompatActivity {
private SurfaceView mySurfaceView;
private QREader qrEader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final DrawerLayout mDrawerLayout = findViewById(R.id.drawer_layout);
mySurfaceView = (SurfaceView) findViewById(R.id.camera_view);
qrEader = new QREader.Builder(this, mySurfaceView, new QRDataListener() {
@Override
public void onDetected(final String data) {
}
}).facing(QREader.BACK_CAM)
.enableAutofocus(true)
.height(mySurfaceView.getHeight())
.width(mySurfaceView.getWidth())
.build();
}
@Override
protected void onStart() {
super.onStart();
qrEader.start();
}
@Override
protected void onResume() {
super.onResume();
qrEader.initAndStart(mySurfaceView);
isCheck = 0;
}
@Override
protected void onPause() {
super.onPause();
qrEader.releaseAndCleanup();
}
}
`
And this is the xml:
`
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/menu"
layout="@layout/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<SurfaceView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/menu"
android:layout_weight="1" />
</RelativeLayout>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_view"/>
</android.support.v4.widget.DrawerLayout>`
PS: Menu height is 50dp
from qreader.
Any news? please help me
from qreader.
What happens if you remove android:layout_weight="1"
from your SurfaceView?
From what I can tell there's no use for it and it might do some weird measurement things behind the scenes.
Also you have a duplicate declaration of your android XML namespace. Maybe remove the declaration from your RelativeLayout and see if that helps.
from qreader.
There are several issues at play here:
- The
QREader.Builder
requires thewidth
andheight
of the size to be defined at the time the QREader is built. QREader assumes (=requires) thatQREader.initAndStart(SurfaceView surfaceView)
is called before the mentioned final size is calculated, so for example ononResume
which makes it impossible to supply the correct size calculated from aViewTreeObserver.OnGlobalLayoutListener
to the builder - Because of the above (the
QREader
must be created inonCreate
or latest inonResume
), the camera permission must already been granted in the activity / fragment in which the class is used. (The sample app "solves" this by restarting the activity when. Obviously, this solution is not applicable for everyone) - The size as set in the builder is just the requested preview size which means that there is no guarantee that the camera shoves bitmaps onto the
SurfaceView
in exactly that size. Due to the nature how aSurfaceView
works, IIRC, the source bitmap is stretched onto the view. To solve this, one has to manually recalculate the bounds of the bitmap to simulate/reimplement aScaleType.CENTER_CROP
as seen forImageView
s.
from qreader.
We have users in our app where the camera is black. ( on some devices ) we haven't been able to reproduce this issue, however, I think it might have to do something with the SurfaceView not being able to preview the camera on these devices. The reason might be connected to the stretching where some devices just preview a black screen instead of a stretched view. is this possible?
@westnordost do you have some example of how to implement your solution to fix the stretching?
from qreader.
No, I do not have an example (it is not open source), but I can roughly lay it out for you:
Let's say the camera preview is for some reason a square, while the surface view is a 1:2 (portrait) rectangle. One trick to make the camera picture appear non-skewed is to make the surface view itself have the same aspect ratio as the camera picture (in this case, a square) by modifying its margins (and ensuring the parent view clips to bounds, which is the default though anyway).
To achieve something like CENTER_CROP, set negative margins so that width - horizontal margins / (height - vertical margins) = desired aspect ratio, which is 1 in this case.
To achieve something like CENTER_INSIDE, use positive margins.
For the example of the square and the portrait, you would set a negative horizontal margin for CENTER_CROP or a positive vertical margin for CENTER_INSIDE.
from qreader.
Closing as issue is outdated. Please open a new issue if the issue still persists.
from qreader.
Related Issues (20)
- java.lang.IllegalStateException: Camera already started! HOT 3
- Flash feature HOT 2
- Start activity in onDetected() and then pressing back HOT 2
- Surface View stops camera preview HOT 1
- Need Design Logo/Icon/Favicon HOT 1
- OpenGLRenderer: endAllStagingAnimators on 0x55a2950170 (RippleDrawable) with handle 0x55a2661e30 HOT 1
- Barcode recognition libs are not downloaded and are not operational HOT 7
- How can I read QR code once and stop QrReader HOT 7
- Question HOT 1
- setBackgroundDrawable with shape
- milestone for next release HOT 2
- Migrate to Maven Central HOT 1
- Move codebase to Kotlin
- Move all the docs into its own markdown file inside the repo.
- Cleanup readme
- Add tests
- 📖 Guest Book 🙇🏻♂️
- Unable to see preview HOT 5
- Failed resolution of: Lcom/google/android/gms/internal/zzbck;
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 qreader.