我将图像保存到SD卡中,直到我拉出SD卡并将其返回后才会出现在Gallery应用程序中.
你知道为什么会这样吗?
看起来像Gallery应用程序有一些缓存没有更新文件保存...
实际上,我还想在Gallery应用程序中打开刚刚保存的图像并且没有成功,
这是我对此问题的疑问.
我可以按一个按钮,打开原生相机应用程序,然后成功拍照.但是当我在手机上查看图库或照片原生应用时,图片不会保存在那里.我对Android很新,所以很可能我在代码中遗漏了一些重要内容.
问题:
1)这些图片在哪里保存?
2)我可以以某种方式修改以下代码以保存到内部存储,因此使用我的应用程序拍摄的所有照片都是私密的,只能通过我的应用程序访问吗?
3)如果我想将这些图片保存到一个对象,以及一些文本/其他输入,那么最好的方法是什么?我应该保存一个Uri或一些标识符以便稍后引用图像,还是保存实际BitMap图像?
非常感谢任何帮助,谢谢!
这是我拍摄照片的代码:
mImageButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = CameraUtils.getOutputMediaFileUri(CameraUtils.MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, REQUEST_IMAGE);
}
}
Run Code Online (Sandbox Code Playgroud)
CameraUtils直接从Google开发者指南中获取的课程:
public static Uri getOutputMediaFileUri(int type)
{
return Uri.fromFile(getOutputMediaFile(type));
}
public static File getOutputMediaFile(int type)
{
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "camera");
if (!mediaStorageDir.exists())
{
if (!mediaStorageDir.mkdirs())
{
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if (type == …Run Code Online (Sandbox Code Playgroud) 我正在使用此代码保存图像:
URL url = null;
try {
url = new URL("image");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e1) {
e1.printStackTrace();
}
OutputStream output;
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/folder name/");
dir.mkdirs();
File file = new File(dir, image + ".png");
Toast.makeText(HomeActivity.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
try {
output = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
}
catch (Exception e) { …Run Code Online (Sandbox Code Playgroud) 我的应用程序在外部存储(/ sdcard)上创建图片文件.我希望这些图像可以从Gallery中查看(不要在Gallery中打开它们,只要用户切换到Gallery就可以查看).有没有办法实现这个目标?