Android's standard default memory allocated for each application is 16M. So it is very valuable, when creating the application to save as much memory as possible, but when loading some large files, compared to the film is quite memory, a 1.3M picture, the resolution is 2560x1920 (width × high) picture when loaded into the memory of the phone will request 19M of memory, This is far beyond the system's own memory space, this time the application will be hung up, so we want to do the image zoom processing, I will take you to create a picture to zoom the application;
The application is as follows:
Implementation of the core code:
Package Com.examp.loadpicture;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.bitmapfactory.options;import Android.os.Bundle;import Android.view.display;import Android.view.view;import Android.view.windowmanager;import Android.widget.ImageView; public class Mainactivity extends Activity {private ImageView iv;private int windowheight;private int windowwidth; @Overri deprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); iv = (ImageView) Findviewbyid (R.ID.IV);//Gets the form size of the phone's screen windowmanager WindowManager = ( WindowManager) Getsystemservice (window_service);D isplay Display = Windowmanager.getdefaultdisplay (); windowHeight = Display.getheight (); windowwidth = Display.getwidth ();} public void LoadPicture (view view) {//Bitmap factory class//Bitmap Bitmap = Bitmapfactory.decodefile ("/sdcard/x.jpg");//encode the specified file, Convert to Bitmap//Iv.setimagebitmap (bitmap);//Image resolution configuration of the class options options= new Options ();//Do not really do picture parsing, just get to the image of the header information: Width x High date options.injustdecodebounds = true;// Set the target file of the image resolution class Bitmapfactory.decodefile ("/sdcard/x.jpg", options);//Get the picture's height x width int imageheight = Options.outheight;int ImageWidth = Options.outwidth; System.out.println ("High of the Picture:" + imageheight + "picture width:" + imagewidth);//Use the width of the picture and the width of the screen to calculate the ratio int ScaleX = Imagewidth/window Width;int ScaleY = imageheight/windowheight;//default proportional int scale = 1;IF (ScaleX > ScaleY & ScaleY >= 1) {scales = ScaleX;} if (ScaleY > ScaleX & ScaleX >= 1) {scale = ScaleY;} Set the picture parser really to parse the picture Options.injustdecodebounds = false;//Set the parsed sample rate, set the value to scale 1/scaleoptions.insamplesize = scale;// Get the picture bitmap again and set the sample rate bitmap bitmap = bitmapfactory.decodefile ("/sdcard/x.jpg", options); Iv.setimagebitmap (bitmap);}}
Demo Download:
http://download.csdn.net/detail/u011936142/7448597