- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试从我的应用程序内部打开 Gallery 内置应用程序中的图像/图片。
我有图片的 URI(图片位于 SD 卡上)。
你有什么建议吗?
最佳答案
这是一个完整的解决方案。我刚刚使用@mad 在下面的答案中提供的信息更新了这个示例代码。另请查看@Khobaib 提供的以下解决方案,解释如何处理 picasa 图像。
我刚刚回顾了我的原始答案,并创建了一个简单的 Android Studio 项目,您可以从 github 中 check out 并直接导入您的系统。
https://github.com/hanscappelle/SO-2169649
(注意多文件选择仍然需要工作)
感谢用户 mad,支持来自文件浏览器的图像。
public class BrowsePictureActivity extends Activity {
// this is the action code we use in our intent,
// this way we know we're looking at the response from our own action
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.Button01)
.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
/**
* helper to retrieve the path of an image URI
*/
public String getPath(Uri uri) {
// just some safety built in
if( uri == null ) {
// TODO perform some logging or show user feedback
return null;
}
// try to retrieve the image from the media store first
// this will only work for images selected from gallery
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if( cursor != null ){
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
return path;
}
// this is our fallback here
return uri.getPath();
}
}
由于有人在评论中要求提供该信息,因此最好收集信息。
在 Intent 上设置一个额外的参数EXTRA_ALLOW_MULTIPLE
:
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
并在结果处理中检查该参数:
if (Intent.ACTION_SEND_MULTIPLE.equals(data.getAction()))
&& Intent.hasExtra(Intent.EXTRA_STREAM)) {
// retrieve a collection of selected images
ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
// iterate over these images
if( list != null ) {
for (Parcelable parcel : list) {
Uri uri = (Uri) parcel;
// TODO handle the images one by one here
}
}
}
请注意,这仅受 API 级别 18+ 支持。
关于android - 以编程方式从 Android 的内置 Gallery 应用程序中获取/选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10452051/
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: how to disable fling in android gallery 我有一个带有 Gallery
我像这样使用 Lightbox: $('#gallery a').lightBox(); html 看起来像这样:
如果之前有人问过这个问题,我深表歉意,但我已经尝试用谷歌搜索这个主题,但没有任何好的结果。基本上,我正在尝试寻找 Google 已决定弃用的 Gallery 小部件的替代品。到目前为止,我有以下候选人
使用Blueimg Gallery我想知道如何在单击 img class=".slide-content" 希望有帮助。 关于jquery - Blueimp 画廊 : Always show "bl
我希望有一个 android 画廊,可以容纳不同宽高比的图像。我想要的是画廊中图像的 CENTER_CROP。然而,当我将图像缩放类型设置为此时,图像会超出图库图像边界。 当然,FIT_XY 会导致图
我正在为 ipad 构建一个应用程序,它使用 youtube api 来获取视频缩略图并将其呈现在图库中(就像 ipad 上的 native youtube 应用程序一样)。基本上它只是 UIScro
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
这应该是关于MEDIA RESCAN的常见问题解答 我的环境: 安卓 4.1.1 com.android.gallery3d 是管理缓存和缩略图的 Gallery 应用程序包。 图库首选项位于: /d
我正在做一个 phoneGap 应用程序,它对图片进行一些更改并将其保存回//sdcard/Download/文件夹。使用 ES File Explorer 等第三方应用程序,我可以看到图片已添加到下
我有一个展示一些扑克牌图像的画廊。每张卡片之间间隔 20dp。 当我从一张图片移动到下一张图片时,画廊会略微滚动到下一张图片之外,然后自行更正回图片。 另一个几乎肯定相关的问题是图像没有干净地滚动到视
大家好,请帮我解决一下 android 中的菜单问题。我想将此画廊作为我的应用程序的网格菜单。请指导我如何将名称放在图像下,如果 iclick 在特定图像上,新 Activity 应该打开,最后单击菜
我想构建一个图库应用,从我的文件夹中获取照片列表并将其显示在一个页面中。 我降低了图像的分辨率,这样图库加载速度会更快,但加载仍然需要很长时间。 我认为问题是每次打开应用程序时都会加载每个文件。我该如
我正在考虑启动一个能够根据标签搜索/过滤图像的图库应用程序。我的问题: 我想经常更新图像,所以...我应该在网络服务器上托管图像并托管应用程序可以调用的 XML 文件,其中包含图像路径、缩略图路径和标
好的,所以我最近刚刚学会了如何使用 jquery 来切换目标 div 的图像源,但是生成的图像加载了一个损坏的链接。有一段时间,我什至不知道如何尝试这样做。事实上,脚本实际上改变了目标 div 的图像
我有一个问题,也许是一个愚蠢的问题,但我认为它很重要。 为什么参数:convertView(View)就对了 public View getView(int position, View conver
默认情况下,当单击图库项目时,图库会自动滚动以将被单击的项目居中。我怎样才能覆盖这种行为?我不希望画廊在单击时滚动到中心,我希望它留在原处。 最佳答案 我认为这是一个正确的解决方案: @Ove
我查看了 API 演示,他们有一个画廊示例,其中仅显示文本,代码仅使用 Cursor ,但我想使用 String 数组。我怎样才能实现使用它?这是 API 演示中示例的代码: Curs
imageView.setLayoutParams(new Gallery.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowMa
我在我的应用中使用了图库。 因为我在每个图库项目中都有两张图片,如下所示 每张兔子和老鼠的图片都合并为一个图库项目。 所以我为两个图像都提供了 onclickListener,但如果我这样提供,我就无
是否可以使用此项目中的异步图像加载器 http://open-pim.com/tmp/LazyList.zip与画廊小部件?我试过: public View getView(int posi
我是一名优秀的程序员,十分优秀!