How does android save a Bitmap object to the SD card?

Source: Internet
Author: User

How does android save a Bitmap object to the SD card?

 How does android save a Bitmap object to the SD card?

This article mainly introduces how android saves a Bitmap object to the SD card. It involves how Android reads and writes SD card data. For more information, see

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

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 logoStream

Byte [] logoBuf = logoStream. toByteArray ();

// Save the image to byte []

Bitmap temp = BitmapFactory. decodeByteArray (logoBuf, 0, logoBuf. length );

// Read the image from byte [] to generate the Bitmap object temp

SaveMyBitmap ("tttt", temp );

// Save the image to the SD card

Public void saveMyBitmap (String bitName, Bitmap mBitmap ){

File f = new File ("/sdcard/" + bitName + ". png ");

Try {

F. createNewFile ();

} 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, 100, fOut );

Try {

FOut. flush ();

} Catch (IOException e ){

E. printStackTrace ();

}

Try {

FOut. close ();

} Catch (IOException e ){

E. printStackTrace ();

}

}

I hope this article will help you design 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.