- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个简单的应用程序来将位图保存在内部存储中,并能够像任何其他图像一样在 Android 图库中显示该位图。
问题是:保存后它没有显示在图库中......而且我不知道我做错了什么。 (我正在模拟器上测试这个)
这是我处理位图保存的类。当我单击按钮保存位图时,在我的主要 Activity 中使用此 Saver 类。
public class Saver {
private Context mContext;
private String mNameOfFolder = "Storager";
private String mNameOfFile = "Quote";
public void saveImage(Context context, Bitmap imageToSave) {
mContext = context;
// Create the directory
File dir = mContext.getDir(mNameOfFolder, Context.MODE_PRIVATE);
String filePath = dir.getAbsolutePath();
// Get the current date and time to attach to the name of the image
String currentDateAndTime = getCurrentDateAndTime();
if(!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, mNameOfFile + currentDateAndTime + ".jpg");
try {
FileOutputStream out = new FileOutputStream(file);
imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
galleryAddPic(file);
successSave();
} catch (FileNotFoundException e) {
Log.d("d", "file not found");
unableToSave();
} catch (IOException e) {
Log.d("d", "IO Exception");
unableToSave();
}
}
private void galleryAddPic(File file) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(file);
mediaScanIntent.setData(contentUri);
mContext.sendBroadcast(mediaScanIntent);
}
private String getCurrentDateAndTime() {
Calendar calendar = Calendar.getInstance();
// Setting format of the time
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
// Getting the formated date as a string
String formattedDate = dateFormat.format(calendar.getTime());
return formattedDate;
}
}
我什至添加了android开发者网站here提供的方法galleryAddPic()能够将图像添加到媒体提供程序的数据库,使其在 Android Gallery 应用程序和其他应用程序中可用。
最佳答案
第三方应用(包括 MediaStore
)无法访问您应用的 internal storage 。如果您希望第三方应用程序能够访问该文件,请使用external storage .
另外,我不知道你为什么要在这里创建一个ContextWrapper
。如果您有需要 Context
的方法(例如,当前代码中的 getDir()
),请在传入的 Context
上调用它们你的方法。
关于java - 保存在内部存储中的位图不会显示在图库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33620177/
这是一个链接:http://lomakincello.net/etu/sehen.php 我正在使用 HTML 和 CSS 创建一个网站。我不熟悉 JavaScript,所以有人帮助我制作了一个运行
大家好。我的目标是为自己的新爱好摄影创建一个个人作品集网站。 目前一切就绪。 (这个可以看here。) 问题是,尽我所能,我无法在 CSS 中替换图像。我花了很长时间试图移动图像等,但它只是悲惨地失败
我对画廊有疑问。我无法通过触摸滚动。通过 DPAD 或轨迹球滚动效果很好。 这是一些代码:xml布局: 适配器: package de.goddchen.android.advent.tem
是否有一个社区站点包含一组自定义控件或他们如何调用它为 View ,人们可以在其中获取和重用或发布比标准 UI 组件集更高级的东西? 最佳答案 OpenIntents.org has a bunch
我看了很多论坛,也试过很多东西,就是无法添加PS图库我在公司代理后面,但我已经设置了我的个人资料来使用它。我正在尝试使用这些命令注册 PS 存储库 [Net.ServicePointManager]:
我目前正在尝试在现有的 C++ 项目中使用 boost 图形库。我想将自定义类的对象存储在 boost 图中。下面是一个小示例,其中包含具有两个成员(一个字符串和一个整数)的自定义类定义及其相应的 g
需要从路径获取图像。我已经尝试了所有方法,但似乎没有得到图像。 我的两个图片路径: /storage/emulated/0/DCIM/Camera/20161025_081413.jpg conten
我正在使用 Turbolinks 开发 Android 和 iOS 网络应用程序。 我正在尝试使用 native View /进程实现拍摄新照片或从图库中选择一张照片。 我的表单中有这一行 当我通过
我正在尝试实现诸如适用于 Android 的 Airbnb 应用程序的效果,列出每行中水平滚动画廊的位置(并且每行都有带标题的顶层)。我在每个单元格中使用带有 FrameLayout 和 ViewPa
好吧,我是编码初学者。我下载了 Galereya Jquery 脚本。它有效,但它与代码中它下面的所有其他内容重叠。我尝试更改溢出和位置,但似乎没有任何效果。当我将它添加到另一个 div 中时,网格停
这是我在 stackoverflow 上的第一篇文章。因此,对于这篇文章中的一些不典型内容,我深表歉意。 我编写了一个带有画廊 slider 的 Django 网站,但我不知道为什么图像太大。看这里:
我正在处理一个网站的图库,它由显示所有图片的缩略图 block 组成以及用于显示特定图像的部分。 这是我用来以实际大小显示缩略图和图像的代码。 问题是:我想不出任何东西来设置打开图像的大小。设
我使用 jquery 制作了一个简单的画廊,但是左右按钮不起作用?? 我使用了 jquery 函数 first().appendTo 和 last().prependTo 请检查下面的链接 Mydem
好的伙计们,请不要杀了我,这是我的第一个问题,我对编程知之甚少:)所以我想用灯箱画廊创建一个简单的网站,你可以看看它here . 所以我无法解决的问题是,当您向下滚动页面时,照片后面没有黑色背景。 我
我正在编写自己的图形库 Graph++ ,我对接口(interface)应该返回什么有疑问。例如,我的 BFS 应该返回什么,我很困惑它是否应该返回按顺序访问的一组 vertices ,或者我应该有
我一直在使用图库控件来显示照片,但在滑动照片时遇到问题。我需要一直滑动才能更改照片,否则它会弹回到上一张照片。 在互联网上查询后,我听说画廊已被弃用。下一个可以与画廊控件执行相同操作的控件是什么? 最
为了上大学,我必须在 android 上开发一个带有面部检测的应用程序。为此,我必须在我的画廊中保存各种照片。问题是保存照片后,图库不会更新。更准确地说,如果我删除了我要保存图像的目录,我打开应用程序
我正在这样使用图库 但是当我运行代码时,我发现画廊从中间开始,我想从左边开始。我该怎么办,请帮助我。 最佳答案 描述有关显示的一般信息的结构,例如其大小、密度和字体缩放。要访问 DisplayMe
我试图让用户从他的设备中选择图像或视频,目前它只显示视频或图像,具体取决于以下代码中首先写入的内容: Intent galleryIntent = new Intent(Intent.ACTION_
我正在创建一个 cover flow通过扩展 Gallery 类来处理图像。 画廊 View 显示正常,但图像从右向左滚动的速度非常快,反之亦然。 有什么方法可以调节图像在水平方向上从右到左移动的速度
我是一名优秀的程序员,十分优秀!