0

I write a code crop image.The image maybe a little big,so I use intent.putExtra("return-data", false); and intent.putExtra("output", outputUri); So I should decode the uri to get bitmap.Just like this(omActivityResult)

InputStream is = null;
is = getContentResolver().openInputStream(outputUri);
Bitmap avatar = BitmapFactory.decodeStream(is);

I first make External Storage to store the crop image.It work well.

outputUri = Uri.fromFile(new File("/storage/emulated/0/upload.jpg"));

But I need to store it in Internal Storage.I follow the Android developer

to save in Internal Storage.The code follow.

FileOutputStream os = null;
    try
    {
        os = openFileOutput("upload.jpg", 0);
    }
    catch (FileNotFoundException e)
    {
    }
    finally
    {
        if (os != null)
        {
            try
            {
                os.close();
            }
            catch (IOException e)
            {
            }
        }

    }

    outputUri = Uri.fromFile(new File(getFilesDir().getAbsolutePath(), "upload.jpg"));

the avatar will be null.I have read many questions in stackoverflow but it doesn't work. Can you help me?

Egos Zhang
  • 1,334
  • 10
  • 18
  • Are you sure that `is` is not `null` after `is = getContentResolver().openInputStream(outputUri);` ? Are you sure that `outputUri` isn't `null` too? – arodriguezdonaire Sep 03 '15 at 07:57
  • store External Storage is not null but store Internal Storage is null. I think somewhere i wrong ,but I can't find it @ Andreu Rodríguez i Donaire – Egos Zhang Sep 03 '15 at 08:00
  • @Andreu Rodríguez i Donaire I try again it won't be null use External Storage – Egos Zhang Sep 03 '15 at 08:06

0 Answers0