Android Read assets picture resource saved to SD card instance

Source: Internet
Author: User
This article for everyone in detail under the Android Read assets picture resources to save the specific implementation of SD card, interested members can refer to Ha, I hope to help you have copy code code as follows:


public class Readbitmap {
public void ReadByte (context C, String name, int indexint) {
byte[] b = null;
int[] Intarrat = C.getresources (). Getintarray (Indexint);
try {
Assetmanager am = null;
am = c.getassets ();
InputStream is = Am.open (name);
for (int i = 0; i < intarrat.length i++) {
b = new Byte[intarrat[i]];
//Read Data
Is.read (b);
Savemybitmap (Bytes2bimap (b), mainactivity.dir+name+i+ ". jpg");
}
Is.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
public static Bitmap Bytes2bimap (byte[] b) {
if (b.length!= 0) {
return Bitmapfactory.decode ByteArray (b, 0, b.length);
} else {
return null;
}
}

public static Boolean Savemybitmap (Bitmap bmp, String path) {
File f = new file (path);
try {
F.createnewfile ();
FileOutputStream fout = new FileOutputStream (f);
Bmp.compress (Bitmap.CompressFormat.JPEG, fout);
FOuT.flush ();
Fout.close ();
return true;
} catch (Exception e) {
//Todo:handle Exception
E.printstacktrace ();
}
return false;
}
}

Related Article

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.