1

Starting off by saying I'm new to the Android language and I need help with something.

I'm trying to get an image from an inputstream connected to my java program and save it to the internal storage and after that I display it. However I'm not recieving any errors at all from my code and yet the image is not displaying at all. There is no problem with my Java program/file since it works 100% with another program I wrote in Java which does the same thing Im trying to do with my Android Application.

public void GetImage()
{

    try
    {
        InputStream inputStream = new BufferedInputStream(connectionSocket.getInputStream());
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        FileOutputStream out = new FileOutputStream(getFilesDir() + "james.png");
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
    }
    catch (IOException e)
    {
        Log.d("ERROR", "GetImage: " + e);
    }
}
public void DisplayImage()
{
    ImageView myImageview = (ImageView) findViewById(R.id.myImageView);
    int imageResource = getResources().getIdentifier(getFilesDir() + "james.png", null, this.getPackageName());
    myImageview.setImageResource(imageResource);
}

Can anyone take a look at the code and tell me what I'm doing wrong? Thank you

Buddvar
  • 13
  • 1
  • 5

1 Answers1

0
    File imgFile = new  File(getFilesDir() + "james.png");

if(imgFile.exists()){
   Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
   ImageView myImageview = (ImageView) findViewById(R.id.myImageView);
   myImageview.setImageBitmap(myBitmap);
}

Please replace your method code with it