gpt4 book ai didi

android - 使用相机拍照,将其保存在本地——而不是 SD 卡

转载 作者:行者123 更新时间:2023-11-29 00:44:33 25 4
gpt4 key购买 nike

如标题所述,我正在尝试启动相机并拍摄一张我可以在本地使用该应用程序的照片。这是针对 Motorola Xoom 的,默认情况下,它们不附带 SD 卡。或者至少我的客户正在考虑购买的产品没有 SD 卡。

我找到了一个关于如何启动相机的非常好的教程,我可以启动它并进行所有操作,以物理方式保存图像,然后能够重新使用该图像。

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

最佳答案

您也许可以将它加载到 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);
}

关于android - 使用相机拍照,将其保存在本地——而不是 SD 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7182596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com