My customers report that saving a bitmap to the gallery gives no
error, but the image is not saved.  Reinstalling the application and
rebooting every few saves seems to help.  So perhaps a handle/object
is being left open??  After a good deal of research, we settled on
this code to save an image to the gallery.  Is there a more reliable
method?

Thanks,
ch

static Uri saveImageToSDcard2 (Context context, Resources res, Bitmap
bm, String name, ContentResolver cr)

{
        Uri uri = null;
        try {
                ContentValues newImage = new ContentValues(2);
                newImage.put(Media.DISPLAY_NAME, name);
                newImage.put(Media.MIME_TYPE, "image/png");

                uri = cr.insert(Media.EXTERNAL_CONTENT_URI, newImage);

                OutputStream out = cr.openOutputStream(uri);
                boolean success = bm.compress(Bitmap.CompressFormat.PNG, 100, 
out);
                out.close();
                if (success)
                        savedOrErrorMessage =
res.getString(R.string.Saved);
                else
                        savedOrErrorMessage =
res.getString(R.string.ErrorSavingToGallery);

        } catch (Exception e){
                // Log.d("Image Writer", "Problem with the image. Stacktrace: 
", e);
                savedOrErrorMessage = 
res.getString(R.string.ErrorSavingToGallery);
                uri = null;
        }
        return uri;
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to