Android displaying a crisp image after zooming - android

Currently I have a set of images which has resolution of 480x640 each.
When I zoom the image using an image displayer library I got from googling (TouchImageView), the image got a bit blurry.
Is it possible to use higher resolution image so that the image will not be blurry when zoomed?
As far as I know, images will be scaled in terms of width in Android, but the height will not be scaled, right?
Here's my code for the image displayer :
<com.km.parkit.TouchImageView
android:id="#+id/overview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:contentDescription="#string/imageDesc"
android:scaleType="matrix"
android:src="#drawable/parkinglot" />

Related

SVG gets blurry when scaled up in ImageView (Android)

I'm trying to add a SVG image to an AppCompatImageView. The image should be the fullscreen background of my application. It is a very wide image that should be scaled up to the device's screen height. The width of the image is simply cut based on the device's screen width.
The problem I'm facing is that the SVG image gets blurry and pixelated when it is scaled up, which shouldn't happen since it's an SVG.
Basic setup
Android project with minSdkVersion 21
SVG should be loaded in an AndroidX AppCompatImageView within a ConstraintLayout
The SVG is located in the drawable folder and is set directly in the xml layout file via app:srcCompat
vectorDrawables.useSupportLibrary = true is enabled in app Gradle
I've tried multiple different SVG images to rule out the possibility that my SVG was broken. I tried different options for converting the SVG to a VectorDrawable including the Android Studio's Vector Asset Studio and multiple external convertors.
I even tried subclassing the AppCompatImageView and do the scaling manually with scaleType matrix, calculating the scaling factor based on the screen size and apply the scaling matrix to the drawable.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="#drawable/background"
app:layout_constraintDimensionRatio="w,651:160"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Expected behaviour would be that the SVG image scales up without any major quality loss. The actual behaviour is that it gets pixelated and blurry.

How to set image fit on every screen with aspect ratio

I have some Images, coming from the the server, I am confuced regarding image resolution. how it is possible to show every image complete on every screen with the aspect ratio.
I need to cover the entire screen with no crop. Image should be complete on every resolution screen.
<ImageView
android:id="#+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
Image coming from server
Picasso.with(context).load(shopDataForAdvs.get(position).getSrc()).fit().placeholder(R.drawable.product_image).error(R.drawable.product_image).into(imageView);
Here I have Image which is streaching
Decided to upgrade my comment to an answer...
Every image has an aspect ratio. Every phone has an aspect ratio. There is no guarantee that these two aspect ratios will be the same, so you have three options:
1 - Stretch the image to fit. This is what android:scaleType="fitXY" and the Picasso fit() call are doing. I don't really recommend this choice, as the image will look "weird", but it is a valid choice.
2 - Crop the image to fit. This would be android:scaleType="centerCrop" and Picasso centerCrop(). This will scale the image up (without stretching it) until the smallest dimension of the image matches the dimension of the phone, and will crop the image in the other dimension.
3 - Letterboxing. This would be android:scaleType="centerInside" or Picasso centerInside(). This will scale the image up (without stretching it) until the largest dimension of the image matches the dimension of the phone, and will leave the rest of the ImageView blank.
I recommend option 2, or perhaps a combination of options 3 and 2 (load the image without cropping, but let the user zoom in if they desire).

ImageView Quality Not Smooth On Edges

I have an ImageView which I display on screen, the quality on the edges is not smooth, this is on emulator and on real device.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/temp_9" />
I have attached a picture to show the difference with the image on the left being from emulator (sharp edges) and the image on the right is the original PNG image (smooth edges).
I have placed image in raw instead of drawable - not working
I have moved the image across the different drawable folders - not working
I have created a generic 'drawable' folder and placed image inside - not working
I have created a 9 path image - not working
I have reduced the image size using GIMP - not working

Add white spaces to an image to fit to a specific resolution

In apps like NoCrop an image is made to fit a resolution of 1:1 (made square) by adding some extra spaces at the top and bottom of the image (shown below).
Similarly, I wish to add some spaces to an image through my Android app, to fit a resolution of ratio, say 16:9. My app creates a video by stitching these images together, and for the video, all the images first need to be converted into a fixed resolution.
I have not used Bitmaps much, nor I am an expert in Android. Any kind of help would be appreciated! :)
Try adding these to your ImageView in xml:
android:scaleType="centerCrop"
android:adjustViewBounds="true"
This will crop your image so that it fits the ImageView

showing image of sixe 64 X 64 on any size imageview without loosing its quality

I am retrieving image from server and setting it to image view.The image size is 64 X 64 .
But I want it to suppport all size image views. If I use imageview of size 150dp X 150dp
it gets blurred out,it stretches.Is there any method so that my image maintains its quality even on bigger size imageview?I had heard to use ninepatch images in drawable but here i'm downloading it from server and image size is fixed 64 X 64 .
Plz Help!!!!
NinePatch is for stretching images, usually only for background images with a single color or a gradient in one direction. So that is not your answer.
As to showing your 64x64 image as 150x150.. no. It's just as if you'd do image enlargement in an image editor - the information is not there. Although it shouldn't be that bad.
Check this to see if any alternative fits your needs:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Typically used:
<ImageView
android:id="#+id/image1"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_height="wrap_content"
android:layout_width="0dp"
/>
I am afraid it can't be done...Not with all image types at least. There are images called VECTOR images which retains quality at significant level of image resizes. So you should try using some vector kinda images which could be of .PNG images, etc.
Because shrinking a larger image works most of the time, but enlarging smaller images will always under distortion.

Categories

Resources