Android ways to save bitmap objects to SD cards _android

Source: Internet
Author: User

The example in this article describes how Android saves bitmap objects to an SD card. Share to everyone for your reference. as follows:

Bitmap Logobitmap = Bitmapfactory.decoderesource (Mcontext.getresources (), R.drawable.arcnote_logo);
Bytearrayoutputstream Logostream = new Bytearrayoutputstream ();
Boolean res = logobitmap.compress (bitmap.compressformat.png,100,logostream);
Read the image to the Logostream byte[] logobuf = Logostream.tobytearray ();
Save image to byte[] Bitmap temp = Bitmapfactory.decodebytearray (logobuf,0,logobuf.length);
Reads the image from byte[] to generate the bitmap object temp savemybitmap ("tttt", temp);
 Save image to sd card public void Savemybitmap (String bitname,bitmap mbitmap) {File f = new File ("/sdcard/" + Bitname + ". png");
 try {f.createnewfile ();
 The catch (IOException e) {//TODO auto-generated catch block} FileOutputStream fout = null;
 try {fout = new FileOutputStream (f);
 catch (Exception e) {e.printstacktrace ();
 } mbitmap.compress (Bitmap.CompressFormat.PNG, fout);
 try {fout.flush ();
 catch (IOException e) {e.printstacktrace ();
 try {fout.close ();
 catch (IOException e) {e.printstacktrace (); }
} 

I hope this article will help you with your Android program.

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.