Android image processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.