I taking an image from a gallery and showing it in ImageView but, after setting the image in ImageView, its shape is completely distorted and it does not maintain the aspect ratio of the original.
Below is an image after setting in ImageView. How can I maintain the aspect ratio of the original?
Related
I need to load some images from URI to Bitmap variables and perform some operation with them togheter. I need the bitmaps to be squared images with fixes size, scaled down and cropped. By now I use this code:
return Picasso.with(c).load(imageUri).resize(size, size).get();
but, obviously, the image will be resized without keep its aspect ratio.
I want to resize the image with these requirements:
the smaller dimension (width or height) should be equals to size
the greater dimension should be cropped to size, keep image centered
The key is using centerInside after resize. See link
Picasso.with(c).load(imageUri).resize(size, size).centerInside().get()
set your imageview height and width fix inside xml and then set image to imageview like
Picasso.with(YourActivityName.this)
.load(imageUri)
.into(imageview_id);
I have attached a image in my android app but when i launch the app it is very small.Please suggest how to increase its size in app so that its clearly visible.
Below is the snippet code of my activity_main.xml :
<ImageView
android:id="#+id/power_image"
android:src="#mipmap/ic_launcher"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_above="#+id/logButton"
android:scaleType="fitCenter"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="false"
android:visibility="visible"
/>
Change your scaleType to centerCrop and it will be worked. Here is full guide about ScaleType in ImageView in Android. The following is a list of all the most common types of scaleType:
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; 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.
In the imageView you have set dimensions as 200dp x 200dp for the imageView.
Set a background color for the imageView eg yellow. This will let you know the amount of area the imageView covers. In case if the imageView doesn't cover the area desirable to you, increase the height and width of the imageView.
In case if the imageView covers enough space but the image is still small and covers only a portion of the yellow area (bg of imageView). Then you can use scaleType = fitxy in imageView, if you dont want to maintain aspect ratio else go for scaleType = centerCrop or centerInside
I want to cut a piece of an Image with a fixed aspect ratio.
The user can choose the area which should be cutted out within a WYSIWYG view.
The final output should be a bitmap with fixed resolution (1300px * 1000px).
The aspect ratio of the WYSIWYG view and the output bitmap is the same.
Preview Image
Simple solution would be upscale the bitmap from the WYSIWYG view to output resolution (would work because aspect ratio is the same) but i want to cut the choosen area from the original input bitmap.
I think the cropper: Cropper is doing the same
How to do that ?
I have a bitmap that is being rendered inside of an imageview.
The scaling is set so the bitmap maintains it's aspect ratio. As such, there is padding on the top and bottom relative to the imageview.
What I'd like to do is get that padding. I'm assuming this is possible no?
I have a background drawable and I want to stretch it horizontally to the screen width and maintain its aspect ratio, but I want to crop it vertically since it will go out of the bottom of the screen.
I can't use an ImageView for some reason and have to use a BitmapDrawable, any help?
Thanks in advance.