Padding out a bitmap to make it a power of two - android

I have a bunch of images of dimension 480x800. The intention is that these will fill the entire screen of the device.
I would like to take the image and use createScaledBitmap() to resize the image to fit the screen exactly. I then want to put this bitmap inside another bitmap (not stretch it), which will have dimensions that are a power of two.
So for example, if the screen size is 320x480 I resize my 480x800 image to be 320x480. I then want to place this 320x480 image inside of a bitmap that is 512x512 so that the original image is nested in the top left corner (with the extra space being blank).
How can I achieve this on android? I have gotten so far as to resize the image to fit the screen exactly, but not making the power of two bitmap and filling it.

Solved this by using a texture atlas

Related

How to stretch a bitmap?

I am porting a Java game to Android and the graphics in this game will not render correctly if the dimensions are not a square. Thus, the screen will not fit exactly onto my device. Is there anyway to stretch a bitmap, which contains the drawings, like an image? I know there is Bitmap.createScaledBitmap(), however this changes the pixel dimensions and thus the view will not render correctly. I want the dimensions to be the same, but the image should fill the whole screen. I can deal with distortions.

Round shaped image is elongated horizontally or vertically

I have to display a splash image which has a round shaped object (a Ball). The Layout for splash is a simple linear layout with just a single Image view to occupy the full screen.
Image : single image with the size of 1280 x 720.
When my splash screen is shown in the App, The round object is shown in different shape in different screen sizes. I hope the aspect ratio and the resolution is the cause for these elongated images.
Could you please suggest an idea / approach to solve this ?
Do I need to consider the aspect ratio or the resolution or both ?
Finally the ball should look like a ball in all the devices :)
Thanks in Advance.
1) Yes, by default Android will scale your image down to fit the ImageView, maintaining the aspect ratio. However, make sure you're setting the image to the ImageView using android:src="..." rather than android:background="...". src= makes it scale the image maintaining aspect ratio, but background= makes it scale and distort the image to make it fit exactly to the size of the ImageView. (You can use a background and a source at the same time though, which can be useful for things like displaying a frame around the main image, using just one ImageView.)
2)You should also see android:adjustViewBounds to make the ImageView resize itself to fit the rescaled image. For example, if you have a rectangular image in what would normally be a square ImageView, adjustViewBounds=true will make it resize the ImageView to be rectangular as well. This then affects how other Views are laid out around the ImageView.
You can change the way it default scales images using the android:scaleType parameter. By the way, the easiest way to discover how this works would simply have been to experiment a bit yourself! Just remember to look at the layouts in the emulator itself (or an actual phone) as the preview in Eclipse is usually wrong.
Reference : How to scale an Image in ImageView to keep the aspect ratio
set imageView property
scaleType="centerInside"
Add scaled versions of the image with the same file name under folders 'res->drawable','res->drawable-ldpi','res->drawable-hdpi' and under xhdpi "http://developer.android.com/guide/practices/screens_support.html#DesigningResources"

Android resource that scales on one axis and tiles on another

We're working on the Android version of one of our games and we're having a problem with a background image. On iOS, it's really easy to scale the image down to the appropriate width and configure it to stretch vertically.
However, on Android, we can't figure out a way to do this. Basically, because of the myriad screen sizes and resolutions, we'd like to have our background image (which frames the play area) scale down to fit the width of the screen. Then, the bottom and top portions of the image should have the right aspect ratio but the middle part should tile (or stretch even) to fill the rest of the area.
We tried this with a nine-patch file but nine-patches don't scale down. We've tried it with LayerDrawables which works well except that it won't tile the middle as the size of the layout changes; it just stretches the entire image instead.
Is there any way to get a drawable to scale to fit horizontally and then tile a section to grow vertically?

Tying images to one another and scaling?

I have an application that needs to scale an image in relation to another image due to different screen size, I have an image that is essentially a background that matches the width of the screen and another image in a relative layout that is aligned so it fits on my phone in 2.2 but when seen on 2.1
Or ... i could just use something that scales the image as a percentage. Suggestions?
edit:
I guess all i need is to know how i can keep an image in a spot relative to another using relative layout and scale it through a percentage, different screen size will scale the other image but not this one because the other image fills the parent so when the screen size is smaller it just scales it down, however the one i need to scale does not because it doesn not fill the parent.

Android: How to center crop images without scaling

I have some images I want to show in thumbnails, and I want them to center crop and not scale. The images themselves are almost always rectangular, and I want to crop them around their center and have them fit into a square ImageView. The bitmaps themselves either have a height that matches the size of the ImageView, or a width that matches. So essentially I just want to crop off the left/right or the top/bottom of each photo, and not lose any quality.
When I try to use ScaleType.CENTER_CROP my images are becoming blurry. Any suggestions?
You should just use ScaleType.CENTER. This will perform no scaling, it will just center the image behind the image frame. Anything falling outside the ImageView will be cropped.

Categories

Resources