How to save the image of Android memory, estimated to be trapped a lot of small partners, today to lead you to realize how to get in-memory images.
Question Description: When we use ViewPage to show pictures, how to save your favorite photos when users swipe to enjoy them?
Problem Solving method: When we see the picture, the picture is in the memory of the phone, we need to download it locally, the specific implementation, see the code:
//download photos from the product display from memoryLinearLayout v = (linearlayout) Pageviewsphoto.Get(Delimagenumber);//get a view of a pictureif(V! =NULL) {ImageView image= (ImageView) V.getchildat (0);//get the picture control inside the viewif(Image! =NULL) {bitmapdrawable drawable= (bitmapdrawable) image.getdrawable ();//get a picture from a picture controlif(Drawable! =NULL) {Bitmap Bmpicon= Drawable.getbitmap ();//convert a picture to bitmap}}}
Pageviewsphoto is our ViewPage control, Delimagenumber is the one we're going to download, the number shown in ViewPage
Here about the download of the picture has been completed, we get the image of the bitmap format, the following to introduce you how to scale the size of the picture
Thumbnailutils: is a class that Google offers to zoom the picture
New= T.extractthumbnail (Bmpicon,N,+); // picture scaling--android Self-band Method
How do we save images to a local phone?
//save photos to your phone locally Public Staticstring Savebitmap (String dir, string path, Bitmap bmp) {string PicturePath=NULL; File Fdir=NewFile (dir); if(fdir.exists () = =false) Fdir.mkdirs (); File F=NewFile (path); FileOutputStream FOut=NULL; Try{FOut=NewFileOutputStream (f);//BMP = Reduce (BMP, N, +, false);//size CompressionBmp.compress (Bitmap.CompressFormat.JPEG, the, FOut); Fout.close (); } Catch(Exception e) {e.printstacktrace (); } if(F.exists ()) {LOG.D ("123","123"); } Else{LOG.D ("123","123"); } PicturePath=F.getabsolutepath (); returnPicturePath; }
Android image processing