How to load an ImageView from a png file?(如何从 png 文件中加载 ImageView?)
问题描述
我用相机拍照
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 22 );
活动完成后,我将位图图片写入 PNG 文件.
When the activity completes, I write the bitmap picture out to a PNG file.
java.io.FileOutputStream out = openFileOutput("myfile.png", Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
没问题,我可以看到文件是在我的应用私有数据空间中创建的.
That goes OK, and I can see the file is created in my app private data space.
稍后我想使用 ImageView 显示该图像时遇到了困难.
I'm having difficulty when I later want to display that image using an ImageView.
任何人都可以建议代码来执行此操作吗?
Can anyone suggest code to do this?
如果我尝试创建一个包含路径分隔符的文件,它会失败.如果我尝试从不带分隔符的名称创建 Uri,则会失败.
If I try to create a File with path separators in, it fails. If I try to create a Uri from a name without separators, that fails.
我可以使用以下命令打开文件OK:
I can open the file OK using:
java.io.FileInputStream in = openFileInput("myfile.png");
但这并没有给我设置图像所需的 Uri
But that doesn't give me the Uri I need to set an image with
iv.setImageURI(u)
总结:我在私人应用数据中的 png 文件中有图片.将其设置为 ImageView 的代码是什么?
Summary: I have the picture in a png file in private app data. What's the code to set that into an ImageView?
谢谢.
推荐答案
尝试 BitmapFactory.decodeFile() 然后 setImageBitmap() 在 ImageView代码>.
Try BitmapFactory.decodeFile() and then setImageBitmap() on the ImageView.
这篇关于如何从 png 文件中加载 ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 png 文件中加载 ImageView?
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
