I am developing a photoshop application for the G1 where you can apply
different filters to your pictures stored in the pictures folder. So I
use a gallery and a cursor to select the picture I want to manipulate,
copy the picture to a bitmap so I can perform some filter operations
and afterwards save the new bitmap as a new file to the phone. So I
figured out that there are basically two options I have to save the
image. One is to use the MediaStore.Images.Media.insertImage()
methode, which generally would work, but I don't want a thumbnail to
be created. The second option, which I actually use, is to use an
OutputStrem.

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);
}

This snippet can also be found in the devguide (http://
developer.android.com/guide/topics/providers/content-providers.html)
and it saves the image to the phone's photo album. However, after the
image is stored on the phone, I cannot open the picture gallery in the
main menu again. An unknown exception is thrown. I'm still able to
access the gallery using the camera menu and it also works fine within
my application, but anyhow I have to reboot the phone to access the
gallery using the pictures shortcut in the main menu.

Using the insertImage() method I don't have this problem. The image
subsequently appears in the gallery after saving it and I can open the
gallery from the main menu but using the OutputStream, the gallery
crashes when I try to open it and it is not displayed immediatly in
the gallery of my application.

Does anybody know what I am doing wrong?

--~--~---------~--~----~------------~-------~--~----~
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