I\'ve got an ImageView wrapping this image:
if you try to add the large size image for eg let say 4~6 mb and you are using the drawable,then you would get the error like->java.lang.RuntimeException: Canvas: trying to draw too large(537528960bytes) bitmap
For java do this in your android studio, but the concept remains same for others also,do this to insert the image in your app in the background, applicable for both large and small size images.
Basically move your image in the (hi-res) drawable to drawable-xxhdpi which would be finded by going in the app->res->mipmap.
<ImageView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/imagename" />
To display original image size in Imageview write down following.
android:layout_height="wrap_content"
and android:adjustViewBounds="true"
do the job. No need to set ScaleType.
<ImageView
android:id="@+id/iv_QuestionImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:adjustViewBounds="true"
android:src="@drawable/ic_app_icon_512"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Add the following fields to ImageView:
android:scaleType="fitXY"
android:adjustViewBounds="true"