2

正如标题所述,我正在尝试启动相机并拍摄可以在本地与 APP 一起使用的照片。这适用于摩托罗拉 Xoom,默认情况下,它们不附带 SD 卡。或者至少我的客户正在考虑购买的那些没有 SD 卡。

我找到了一个关于如何启动相机的非常好的教程,我可以让它启动,一切都可以物理保存图像,然后能够重新使用该图像。

我发现的许多解决方案或其他教程只显示了如何保存到 SD 卡——而不是常驻内存或应用程序本地。看起来可以这样做,但我很难过。:-/

4

3 回答 3

2

您也许可以将其加载到 ContentProvider 以便以后可以将图像用于任何事情:

// Add some parameters to the image that will be stored in the Image ContentProvider
int UNIQUE_BUCKET_ID = 1337;
ContentValues values = new ContentValues(7);
values.put(MediaStore.Images.Media.DISPLAY_NAME,"name of the picture");
values.put(MediaStore.Images.Media.TITLE,"Thats the title of the image");
values.put(MediaStore.Images.Media.DESCRIPTION, "Some description");
values.put(MediaStore.Images.Media.BUCKET_DISPLAY_NAME,"Album name"); 
values.put(MediaStore.Images.Media.BUCKET_ID,UNIQUE_BUCKET_ID);
values.put(MediaStore.Images.Media.DATE_TAKEN,System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

// Inserting the image meta data inside the content provider
Uri uri = getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);

// Filling the real data returned by the picture callback function into the content provider
try {
    OutputStream outStream = getContentResolver().openOutputStream(uri);
    outStream.write(buffer);  // buffer is the data stream returned by the picture callback
    outStream.close();
}catch (Exception e) {
    Log.e(TAG, "Exception while writing image", e);
}
于 2011-08-24T22:05:10.460 回答
0

因此,您应该注意的一件事是,当您调用 时Environment.getExternalStorageDirectory(),这不一定对应于外部存储空间(即和 SD 卡),并且会在没有 SD 卡插槽的设备上返回本地存储空间。

注意:不要被这里的“外部”这个词弄糊涂了。最好将此目录视为媒体/共享存储。它是一个文件系统,可以保存相对大量的数据,并且在所有应用程序之间共享(不强制执行权限)。传统上这是一张 SD 卡,但它也可以作为设备中的内置存储实现,与受保护的内部存储不同,并且可以作为文件系统安装在计算机上。

http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory ()

这同样适用于Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

于 2011-08-24T23:40:18.777 回答
0

查看Activity.getFilesDir()Activity.getCacheDir()它们提供对存储应用程序的存储的访问。还要查看Environment.getExternalStoragePublicDirectory (),这里的外部是指在应用程序的私有目录之外。还有其他几个,因此请查看 API 的类似命名方法以找到最适合您的方法。

于 2011-08-24T21:44:49.613 回答