Create an image from part of an image in Android?

| | August 4, 2015

I’m a computer science student and a beginning Android developer, learning on the job. My boss, a small business owner, paid another programmer to create an iOS app. Now he’s paying me to create the Android version. He sent me the image assets used for buttons and backgrounds. The app mostly displays text, and it has a textured background from an image.

Because iOS has only a few screen sizes, it was relatively easy for them to create a background image for each screen size.

I’d like to be able to have the same background, but the logistics are more complex with Android.

My proposed solution dynamically cut out a screen size image from a larger image, and make it the background.

My plan was to crop the larger image to screen size with a Bitmap file, and then set it the main screen in onCreate(). This S.O. post gave me the idea to do that.

I was wondering if anyone has tried this before?

Could this be a good solution?

Also:
1) How can I dynamically obtain the screen size, to determine the correct size of the background image?
2) What units should I use for cropping the Larger image? When I use
createBitmap(Bitmap source, int x, int y, int width, int height)
what should be the unit for width and height?

+----------------------------------------+  
| x x x x x x x x x x x x x x x x x x x x|
|x x x x x x x x x x x x x x x x x x x x |
| x x x x x x x x x x x x x x x x x x x x|
|x x x x x x x x x x x x x x x x x x x x |
| x x x x x x +--------------------------+                           
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|    
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|   
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|    
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|  
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|    
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|   
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|    
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|  
|x x x x x x x|x x x x x x x x x x x x x |
| x x x x x x | x x x x x x x x x x x x x|     
+----------------------------------------+

Leave a Reply