如何加载从PNG文件的ImageView的?加载、文件、PNG、ImageView

2023-09-05 06:09:23 作者:奋斗之路加满油

我拿的相机拍摄照片用

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.

任何人都可以提出code做到这一点?

Can anyone suggest code to do this?

如果我尝试创建一个文件路径分隔符,它失败。 如果我尝试从没有分离器的名称创建一个开放的,失败。

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.

我的可以的使用打开该文件确定:

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文件。什么是code到设置成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.de codeFILE()然后 setImageBitmap( )的ImageView