Created
October 22, 2010 05:27
-
-
Save skatldjs/640000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.provider.MediaStore.Images.Media; | |
import android.content.ContentValues; | |
import java.io.OutputStream; | |
// Save the name and description of an image in a ContentValues map. | |
ContentValues values = new ContentValues(3); | |
values.put(Media.DISPLAY_NAME, "road_trip_1"); | |
values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles"); | |
values.put(Media.MIME_TYPE, "image/jpeg"); | |
// Add a new record without the bitmap, but with the values just set. | |
// insert() returns the URI of the new record. | |
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); | |
// Now get a handle to the file for that record, and save the data into it. | |
// Here, sourceBitmap is a Bitmap object representing the file to save to the database. | |
try { | |
OutputStream outStream = getContentResolver().openOutputStream(uri); | |
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream); | |
outStream.close(); | |
} catch (Exception e) { | |
Log.e(TAG, "exception while writing image", e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment