LMaker
LMaker

Reputation: 1630

Taken photo is bigger than the preview in cameraview

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?

Upvotes: 0

Views: 893

Answers (1)

Morteza Darzi
Morteza Darzi

Reputation: 43

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

Upvotes: 0

Related Questions