Loading and displaying an image has a significant impact on memory usage. For example, the HTC G1 phone carries a 3.2 million-pixel camera. Cameras with 3.2 million pixels usually capture 2048x1536 pixels. Displaying a 32-bit image of this size will require memory of more than 663kb or about 13 MB. Although our applications may not necessarily exhaust the memory, this will certainly make the memory more easily exhausted.
Android provides an application class named bitmapfactory, which provides a series of static methods that allow loading bitmap images from various sources. For our needs, images will be loaded from the file and displayed in the initial activity. Fortunately, the available methods in bitmapfactory call the bitmapfactory. Options class, which allows us to define how bitmap is read into memory. Specifically, when loading an image, you can set the sampling size that bitmapfactory should use. Specify the insamlpesize parameter in bitmapfactory. options, which indicates the proportion of the bitmap image to be loaded. For example, here we set insamlpesize to 8, which will produce an image of 1/8 size of the original image.