Android Studio: Scale ImageView Boundary to fit within Image - android

I want to scale the borders to fit the image. In my file explorer, the image is small and has fit, But hasn't fit in android Studio
If I scale the width and height to a specific value, the whole image shrinks:
Like this
Edit: I got it by changing the scaleX and scaleY

the empty space around image exist in your image , so edit your image and make sure that you crop the image so it just contain what you want.

Related

Is image cropping possible in an Android app?

Is it possible to crop an image on Android?
For example:
If the image must fit in a 400w x 400h space and it is 600w x 400h, can you horizontally center align it within the 400w x 400h placeholder space and crop out 100 pixels on the left and 100 pixels on the right.
OR
If the image must fit in a 400w x 400h space and it is 400w x 600h, can you vertically center align it to the image placeholder and crop out 100 pixels on the top and 100 pixels on the bottom.
This may also apply to images of many different resolutions coming in from a server - regardless of the resolution of the image, can you accomplish the above?
I found this but this is specifically for users to be able to crop their images manually in the app (https://medium.com/mindorks/android-top-image-cropper-libraries-3bc4a4f8f2df), but I need to have the image pull in to a set placeholder size in the app from the API.
Thanks!

How do you add a trimmed circular button image to your android drawable folder?

I'm trying to make a basic media player. I downloaded a free .png from a website for the circular play button but when I just copy and paste it into the drawable folder and add it as my ImageButton I can't scale it down to be the size of my other buttons and the background is gray.
How would I scale the button down and trim out the gray background?
1. You can scale the image so that it works on multiple devices by doing something like this:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Image img = yourImage.getScaledInstance((width * .10), (height * .10), Image.SCALE_DEFAULT);)
This is just an example, but it would resize the image so that it is close to a tenth of the size.
2. Another method would be to simply resize the image with a program like paint, and have the image much smaller. Although this is an immediate easy fix, the image size is not responsive to actual screen size.
3. ScaleType attribute is also a means to change size depending on how you are using the image asset in your code. (thank Parth Patel)
I used an ImageView instead which can basically do anything a button can and scaled it down. Looks great, thank you to #ParthPatel for giving me the answer.

ImageView crop and scale image to smaller size

I am trying to get my images to appear in my image view so that if an image is say 600x400 and my image view is 200x200 that the image is scaled to 300x200 and then the extra width is cropped out so that the image appears as a 200x200 image. I have played with the various ScaleTypes but i can't find one that suits what i want. I want something like a combo of ScaleType.FIT_XY and ScaleType.CENTER_CROP
What you need to do is to scale down the image using the inSampleSize as shown here:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
and then use ScaleType.CENTER_CROP to show the image in the view.

Android ImageView scaling

I am using google graph to get the desired graph for me and display it on a android device.
Now I want to display the received graph on a tablet screen but google graph api supports only 300,000 pixels as a max size (width x height) graph.
I am making a request for 500 x 600 px image and display it on a ImageView. I set the scaleType to fitXy and give the imageView width=fill_parrent height=850dpi because I want the image to almost fill the screen.
The problem is that the background of the image goes light gray or blurring after the ImageView scales the image and it looks bad on the white background of my application... If I make the ImageView wrap_content on width and height the graph has white background.
Is there any way to get the image displayed without changing it's background color?
Please note that I don't want to change the image's size.
I'd recommend to instead use width match_parent and then setAdjustViewBounds=true
If that doesn't fix it you probarbly have to change the image.
Unfortunately I had to change the image to a bigger one and the problem disappeared.

how to scale an image in an ImageView so that it "fits"

I want to scale an image in an ImageView in the following way. The ImageView has some dimensions Width (W) and Height (H). The image I'm putting into the image view could be smaller or bigger than WxH. I want it to scale while preserving aspect ratio to fill WxH space.
It seems like the closest thing to what I want is android:scaleType="centerInside", but what I'm seeing is that if the image is smaller than WxH, it will put a small-unscaled version of that image in the center of the ImageView (like the documentation says), but I want it to scale it to "fit", while showing the entire image, and stretching it to the maximum possible size of the container without cropping anything. In other words, stretch preserving aspect ratio until either the width or the height bumps into the edge of the container (ImageView).
This seems like an obvious thing to want to do, but I can't get it to work this way!!!
From the Android docs...
public static final Matrix.ScaleToFit CENTER
Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.
The XML attribute for this is...
android:scaleType="fitCenter"

Categories

Resources