Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the meaning of ImageView.ScaleType="MATRIX" : Android

I know about the matrix, its structure and working about image view's scale-type. but,

  1. I can't find the exact meaning of ImageView.ScaleType="MATRIX". By declaring this, what exactly happens while drawing the image view.

  2. When can I use ImageView.ScaleType="MATRIX" ?

  3. How does it differ from FIT_END & FIT_START

I googled about it and also referred the official link but was not able to find the exact answer.

like image 992
Mayur R. Amipara Avatar asked Aug 03 '15 12:08

Mayur R. Amipara


People also ask

What is the ImageView in android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.

What is ScaleType?

ScaleType is used for uniformly scaling the image bounds to the ImageView. Android ImageView provides various types of ScaleType for different configurations. CENTER. CENTER_CROP. CENTER_INSIDE.

Which attribute is used to set an image in ImageView in android?

An ImageView control is used to display images in Android applications. An image can be displayed by assigning it to the ImageView control and including the android:src attribute in the XML definition of the control.


2 Answers

  1. ImageView.ScaleType.MATRIX lets you use a Matrix to scale the image. You can set the Matrix using ImageView.setImageMatrix(matrix). So by declaring the scaleType to MATRIX you are saying that you want to use an explicit Matrix to do that.
  2. You can use imageView.setScaleType(ImageView.ScaleType.MATRIX) whenever you want to customize the way the your image scales, rotates, etc. at your desire.
  3. FIT_END and FIT_START are default types of scale. So, if you use FIT_END for instance, your image will maintain the original aspect ratio and it will align the result of the right and bottom edges of your image view. So basically, the difference is that FIT_END and FIT_START are "presets" while with MATRIX you declare that you want to use your own matrix to scale.

Read the docs for more info

like image 169
bitsoverflow Avatar answered Oct 21 '22 18:10

bitsoverflow


As per my understanding, Use below details for each ImageView's ScaleType attributes

center

Displays the image centered in the view with no scaling.

centerCrop

Scales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view.

centerInside

Scales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center.

fitCenter

Scales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view.

fitStart

Same as fitCenter but aligned to the top left of the view.

fitEnd

Same as fitCenter but aligned to the bottom right of the view.

fitXY

Scales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio.

matrix

Scales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

like image 32
Durgesh Patel Avatar answered Oct 21 '22 20:10

Durgesh Patel