【问题标题】:Displaying image from gallery in Oncreate method without opening gallery intent在 Oncreate 方法中显示来自画廊的图像而不打开画廊意图
【发布时间】:2017-01-30 06:37:42
【问题描述】:

我知道如何打开画廊意图并在图像视图中显示。

但我在 oncreate 方法中自动选择图像并在图像视图中显示时遇到问题。

我在画廊文件夹中有一张名为“myfile.jpg”的图片

谁能指导我如何在不打开画廊意图的情况下做到这一点。

提前谢谢你

【问题讨论】:

标签: android android-intent


【解决方案1】:

这里是解决方案:

ImageView image = (ImageView)findViewById(R.id.myImage);

File root = Environment.getExternalStorageDirectory();
String path = root.getAbsolutePath();
path = path + File.separator + "myfile.jpg"; //where you image file located

Bitmap myBitmap = BitmapFactory.decodeFile(path);

image.setImageBitmap(myBitmap);

【讨论】:

  • 不要使用位图。由于您有图像路径,请使用image.setImageURI(uri); 而不是位图。
  • BitmapFactory.decodeFile(path); 导致内存问题。而是使用任何 Imageloader,例如 GlidePicasso 等。
  • Eswar 和 Wizard ,基本上如果我有图像路径,那么我使用毕加索。这只是一个例子。
  • 非常感谢 Deepak Kumar,可以将此图片上传到我的网络服务器吗?
  • 你能帮帮我吗?我有在按钮点击中工作的代码,很抱歉,我是 android 的新手
猜你喜欢
  • 2019-09-13
  • 1970-01-01
  • 2014-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多