0

I'm facing a problem using a Samsung J1 device here. But the image taken is bigger than the preview one.

This is the preview that I got: enter image description here

and this is the final bitmap result:

enter image description here

I'm calling camera view with this attributes:

<com.otaliastudios.cameraview.CameraView
android:id="@+id/camera"
app:cameraGesturePinch="zoom"
app:cameraFlash="auto"
app:cameraAutoFocusResetDelay="0"
app:cameraGestureTap="focusWithMarker"
android:keepScreenOn="true"
app:cameraPreview="glSurface"
app:cameraPictureSizeSmallest="true"
android:adjustViewBounds="true"
app:cameraGestureScrollHorizontal="exposureCorrection"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

I already tried to use cameraPictureSizeAspectRatio with 4:3 but no success with it.

Did I do something wrong?

LMaker
  • 1,444
  • 3
  • 25
  • 38
  • You would need to ask the developers of that library. It looks to me like the preview and the photo match, if you ignore the green brackets. Is that library documented to crop to the area marked by the brackets? – CommonsWare Jul 04 '19 at 14:51
  • nah, the brackets now is just useless. Didnt match because of, look at the preview where the GitHub logo is, at the bottom. And look at the bitmap itself – LMaker Jul 04 '19 at 15:07
  • In the preview, the lower right corner shows the first 3.5 letters of "About", under the overlay. In the photo, the lower right corner shows the first 3.5 letters of "About". – CommonsWare Jul 04 '19 at 15:13
  • Yep, the problem is the height of the image – LMaker Jul 04 '19 at 15:14
  • And I dont know it is AspectRatio problem or not – LMaker Jul 04 '19 at 15:14

1 Answers1

0

i have same problem . after save image from cameraview ( i use camerakit lib) , display file by convert it to bitmap in imageview .

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    cameraKitView = findViewById(R.id.camera)

    val captureButton = findViewById<View>(R.id.button_capture) as Button
    val imageView = findViewById<ImageView>(R.id.myImageView)

    captureButton.setOnClickListener {
        cameraKitView!!.captureImage { _, capturedImage ->
            val savedPhoto = getOutputMediaFile()
            try {
                val outputStream = FileOutputStream(savedPhoto!!.path)
                outputStream.write(capturedImage)
                outputStream.close()
                val myBitmap = BitmapFactory.decodeFile(savedPhoto.getAbsolutePath())
                imageView.setImageBitmap(myBitmap)
            } catch (e: java.io.IOException) {
                e.printStackTrace()
            }
        }
    }
}

and this is my layout :

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<com.camerakit.CameraKitView
    android:id="@+id/camera"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:adjustViewBounds="true"/>

<Button
    android:id="@+id/button_capture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:text="@string/save"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />


<ImageView
    android:id="@+id/myImageView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:alpha="0.5"
    android:adjustViewBounds="true"
    android:background="@android:color/holo_blue_bright"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:contentDescription="@string/app_name" />

</android.support.constraint.ConstraintLayout>

but when show image and want to take another image, cameraview is not as scale as imageview

Solved : just change scaleType to CentreCrop . that is it

Morteza Darzi
  • 33
  • 1
  • 5