How to load an ImageView from a png file?

前端 未结 6 1105
独厮守ぢ
独厮守ぢ 2020-12-29 10:57

I take a picture with the camera using

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 22 );
<         


        
相关标签:
6条回答
  • 2020-12-29 11:11

    Why not this way:

    ImageView MyImageView = (ImageView)findViewById(R.id.imageView1);
    Drawable d = Drawable.createFromPath( PATH TO FILE );
    MyImageView.setImageDrawable(d);
    
    0 讨论(0)
  • 2020-12-29 11:14
    bitmap = BitmapFactory.decodeFile(imageInSD);
    
    0 讨论(0)
  • 2020-12-29 11:18
    iv.setImageURI(Uri.fromFile(in));
    
    0 讨论(0)
  • 2020-12-29 11:22

    Try BitmapFactory.decodeFile() and then setImageBitmap() on the ImageView.

    0 讨论(0)
  • 2020-12-29 11:23

    Also possible:

    java.io.FileInputStream in = openFileInput("myfile.png");
    iv.setImageBitmap(BitmapFactory.decodeStream(in));
    
    0 讨论(0)
  • 2020-12-29 11:25

    There should be no difference between decodeStream() and decodeFile(). decodeFile() method opens an inputstream and calls decodeStream(). This was already answered at this link

    0 讨论(0)
提交回复
热议问题