Saving Bitmap Graphics

You can use the compress() method of the Bitmap class to save a bitmap in various formats. For example, to save the avatar bitmap to a private application JPG file, you could use the following code:

String strAvatarFilename = "avatar.jpg"; avatar.compress(CompressFormat.JPEG,

100, openFileOutput(strAvatarFilename, MODE_PRIVATE));

You can determine the URI address of a file by using the fromFile() method of the Uri class. For example, to determine the URI for the avatar graphics file you just saved using the compress() method, you could use the following: Uri imageUri = Uri.fromFile(new File(getFilesDir(), strAvatarFilename));

After you have saved the avatar to a file and generated the appropriate URI, you can update the ImageButton control contents with the new image. Now, if you run the application and choose an avatar (via the camera or the gallery), the ImageButton control contents will be updated with the appropriate graphic, as shown in Figure 13.6.

Been There, Done That!




The Been There, Done That! settings screen with a custom avatar.


■. 1:

No Password Set j -

pirtli Date:

• * *

No Date fcet


Prefer Not Toi

Was this article helpful?

0 0

Post a comment