Ok I have tried with many different ways rotating the ImageView using Matrix but I can't find how to rotate it without changing its size. I'm trying to rotate a circle, literally a purple circle. This is what happens:
When its on 0, 90, 180, 260 it have the correct size, but when the value is any one between those the image change it size.
Like 0-45 it gets smaller 45-90 it gets bigger until it reaches original size. I know that its doing it because even that the image is a circle its really a square bitmap.
Anyone can help me out?
What minimum API are you using ?
From 11, you can use SetRotationX, it should rotate the view without affecting the image.
Related
I know this is a bit unusual, but I want to resize the bounds of an image without the image itself being scaled down.
For example, when I have an 200x200 image, and resize it to 100x200 the result should just be half of the image, where the other half is just cut.
Is that possible?
I don't know how you resize the image in your app, but if you resize any 200x200 image to 100x200, this result will be a part of your initial image, depending on the starting point.(could be the 1st half starting at pixel 0, the 2nd half starting at pixel 100 or any other half in between depending on the starting pixel)
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'm writing a custom image crop.
I have an image view and a rectangle to choose area for cropping on it.
After cropping I need to know a top-left point of rectangle, that present cropping area.
But when i try to get it, Rect gives me a X, Y and width coordinates of the screen, not image. How can I get a real coordinates of the image?
I guess you could apply a simple proportionnality rule using the actual size in pixels of the device screen (assuming the image is displayed in full screen). You can easily get the screen size using this very complete answer: https://stackoverflow.com/a/1016941/1417179
From there, if your image dimensions is wh and the screen dimensions wshs, you can get the coordinates in image space using image_coordinates = screen_coordinates*w/ws.
You may have to cheat a little if the image displayed is not of the same aspect ratio than the screen, but the idea remains the same.
Hope this helps!
I'm drawing a image that goes from x=0 to the end of the screen and beyond. I would like the screen to move to follow the image for at least 3 screen widhts. How can this be solved?
Thanks!
I created a sprite that is 18 frames long and it is supposed to be stationary and run through the frames and loop the animation, but when it runs it moves slowly across the screen as it animates until it hits the last frame then jerks back to the original position where it was suppose to stay at.
I don't know the reason it does this and have tried to make it smaller sizes and larger sizes, at some sizes it does not move but just animates likes its supposed to do.
If anyone has an answer to why this happens and how to stop it from moving and stay where it is supposed to be it would be greatly appreciated.
I use only 1 row for the sprite and I used gimp to create the sprite and saved it as a png.
The code is rather long thats why I didn't add it but it based on this tutorial
aquarium live wallpaper tutorial
I think I found my answer though, I had the png sprite in a folder I created named drawable, where I put all the images, I tried it again but put the sprite in the other folders this time and it didn't move, I tried scaling the sprite also which made it go a bit wonky, I was hoping on using scaling instead so it stayed the same size for all screens, this works for normal images but for sprites it causes some issues, maybe I'll try that with the largest size in the drawable-large-mdpi folder and see if it causes any issues that way.
I'll update with that method and let you know.
It would be nice to have just one image and scale it instead according to screen size.
Okay I found the answer finally and it might help those creating sprites,the width when divided into the amount frames has to be a whole number since the measurements are in int not float or double, so it moves because when the frame gets divided it came out to a fraction instead which caused it to moves (I guess) whatever that float extra measurement was.
Example: if the sprite was 100 pixels high and 1082 px wide and I had 15 frames the width of each frame would then be 72.133333333px wide for each frame causing an error that would move the image that extra length while keeping the animation looking nice. now if it was 1080px wide each frame would then be 72px wide a nice whole number and then would animate perfectly.
So for those creating there own sprites make sure the wide equals out to be a whole number when the frames get divided (My problem was I was creating one image scaling it down and not checking the width of each frame so only one image size usually work, sometimes I got lucky and got two, I should of figured this out because it all runs in int not float for measuring the width.
Hope this helps out someone else making sprites.
Sam