I am working on listView item in Unity and stuck at fitting the image properly in UI Image. I tried multiple things using Preserver Aspect Ratop, using Filled image type almost every thing but could not make it look fine. In android we call it center crop what i am trying to achieve. First image is with Preserve Aspect while the second one is without it.
What should i do to achieve it.
Thank you.
This is one way to do it that I can think of, using 2 images. The outer image is set at your desired size and have a Mask component:
The inner image is set at center of the outer image and scaled to fit the outer image (either programatically or by hand) It will be cropped by the outer image's mask and only display the area you want.
Related
I'm trying to make a page of cropping profile picture. I have a crop frame which you can drag along. The image is transparent, or blurred, but within the frame, it is clear. The area within the frame will be your profile picture. I know how to set alpha, but I haven't come up with a way to set alpha within the crop frame. So this is the effect I want:
Any help would be great. Thanks!
You should probably think about having two ImageViews. One rectangular for the blurred photo and one circular placed on top of the first one for the crop preview.
When user selects a photo, you would create the blurred copy. It seems you already know how to move the photo within the ImageWiew, and so doing couple of calculations with the widths and heights of the ImageViews and the photo, should give you the correct positioning of the photos in both of the ImageViews to make them align.
Lastly when dragging on either of the ImageViews, adjust the position of the photo in both ImageViews.
This looks promising for circular ImageViews
ImageView in circular through xml
This might have something for efficient image blurring How to blur background images in Android
If you want a different approach, using OpenGL ES, you might be able to achieve realtime blurring outside of the circle with a pixel shader Shader for Android OpenGL ES. Possibly a more elegant solution, but probably not as simple.
I'm not exactly sure if you want blurring or transparency, but the solution will be very similar.
I am using TouchImageView in my app to display images.
https://github.com/MikeOrtiz/TouchImageView
As far as I know, Android does not have an easy way to show an image Top Cropped. The best I can do is to Center Crop the Image, which causes the top and bottom of the image to extend off of the screen.
Is there a way to programmatically scroll my image after it has been loaded, and then call ImageView.setVisibility(true)?
I've tried image.scrollBy(int x, int y);
but I'm not sure exactly how to use it.
I do have the ability to get pixel values for both my screen, and for my image before it is scaled, but don't know what function I should use those values in.
Thanks for your input.
I'm new to android programming and I was wondering about how to get a background image (ImageView) show a drawable with a correct size.
Let me explain well, let's imagine we have this image:
I want this image to get shown with this aspect ratio on all screens.
Since I don't want the image to get stretched, I would like to set manually how my image gets shown, maybe by modifying its scale with thirdy part software.
the problem with this image is that, in portrait mode, it's not guaranteed to see the ball, and so I want to crop the part of my image so that the ball gets shown on the bottom-right edge.
I know that I have to import my drawable for all resolutions, but simply importing does not help... Any suggestions?
EDIT:
I'm facing this problem with dynamic background ImageView, so I'm not going to user xml layout files.
Using scaleType attribute doesn't help for this, or at least not just by setting its value.
I want to make a transparent circle in center of screen and an opaque are on rest of screen. Is this possible with drawable? Or can it be done programmatically.
I have added an image on top of map. Map works perfectly. But problem is I want to support multiple resolutions so I don't want to use different images.
https://www.dropbox.com/sh/yyafqik996p4avp/AABc8ZMKi4pks_BQutQrbg8aa?dl=0
EDIT:
1)Map image is what is my expected output.
2)Mapfilter image is what i want to create using drawable or programmatically.
3)Output image is what i am getting while using below method.
I used this method to draw the second image
http://pastebin.com/MUrH8gmS
I set the output bitmap to my image view using setImageBitmap method
But now the problem is it leaves some space on left and right of image(See Output.png image). How to remove it?
You can use GroundOverlay.GroundOverlay to set the transparent circle image onto the center of the map.
I have an image to be used a background in activity:
I want this image to fit screen by its height.
It means that for wide-screen smartphones, I want my image to be fit by height and centered:
and for square-screen smartphones, I want my image to be cut:
I use ImageView for the image. What scaleType should I use? Looking at the second figure, I'd say to use android:scaleType="centerInside". But looking at the third, I'd say to use android:scaleType="centerCrop". What is correct?
Your evaluation of the different scaleType's is correct. If you want the whole image to be visible, use "centerInside", or if you want to fill the whole view then use centerCrop.
To use a mix of both, you can set the scaleType in your onCreate() method. Based on the behavior you want to have, you can check the orientation or size of the screen and set the appropriate choice.
imageView.setScaleType(ScaleType.CENTER_INSIDE); // or ScaleType.CENTER_CROP
You can have two layouts, one for each of your configurations. You can then load the proper one at the activity's onCreate() call.
When you fit one side of image to background, you will face with two problems, first one is screen width is bigger than image's width or screen height is bigger than image height.So you will have empty space.
If you do not want to face with resolution problem and you want to fit both side of image to background, you need to use centerCROP.But as i said, if one side of image is not enough to fit background, image gets bigger till it will be filled.
Use centerCrop because centerInside doesn't scale an image in a view and you have to create the image with appropriate height to achieve wide-screened smartphones background filling. Or alternative you could use fitCenter to get uniformly scaled image by both axes which fills the all background.