getBitmap() method does not save the screenshot












0















Good afternoon, in my application I shoot video with a mobile camera, then I launch this video thanks



@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
Surface s = new Surface(surface);

try
{
mp = new MediaPlayer();
mp.setDataSource(getVideoFilePath());
mp.setSurface(s);
mp.prepare();

mp.setOnBufferingUpdateListener(this);
mp.setOnCompletionListener(this);
mp.setOnPreparedListener(this);
mp.setOnVideoSizeChangedListener(this);

mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
setPreviewSize(true);
mp.start();
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


I implemented a method that takes a screenshot and saves it to the gallery,



  public void getBitmap(TextureView vv)
{
String mPath = getAndroidImageFolder().getAbsolutePath() + "/" + new SimpleDateFormat("yyyyMM_dd-HHmmss").format(new Date()) + "cameraRecorder.png";
Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();

Bitmap bm = vv.getBitmap();
if(bm == null)
Log.e(TAG,"bitmap is null");

OutputStream fout = null;
File imageFile = new File(mPath);

try {
fout = new FileOutputStream(imageFile);
bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException");
e.printStackTrace();
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
}


But the screenshot does not appear in the gallery and knocks out an error.
That's what produces in Logcat



 E/TextureViewActivity: FileNotFoundException
11-14 15:25:09.961 4143-4143/com. W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/201811_14-152509cameraRecorder.png: open failed: ENOENT (No such file or directory)
11-14 15:25:09.971 4143-4143/com. W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
11-14 15:25:09.971 4143-4143/com. W/System.err: at com.
camera.VideoProcessor.getBitmap(VideoProcessor.java:245)
11-14 15:25:09.971 4143-4143/com. W/System.err: at com.camera.VideoProcessor.onClick(VideoProcessor.java:369)



Here on what part of the code knocks an error




at com.camera.VideoProcessor.getBitmap(VideoProcessor.java:247)  ->  fout = new FileOutputStream(imageFile);


I would be very grateful for your help)










share|improve this question





























    0















    Good afternoon, in my application I shoot video with a mobile camera, then I launch this video thanks



    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
    {
    Surface s = new Surface(surface);

    try
    {
    mp = new MediaPlayer();
    mp.setDataSource(getVideoFilePath());
    mp.setSurface(s);
    mp.prepare();

    mp.setOnBufferingUpdateListener(this);
    mp.setOnCompletionListener(this);
    mp.setOnPreparedListener(this);
    mp.setOnVideoSizeChangedListener(this);

    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
    setPreviewSize(true);
    mp.start();
    }
    catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SecurityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IllegalStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    I implemented a method that takes a screenshot and saves it to the gallery,



      public void getBitmap(TextureView vv)
    {
    String mPath = getAndroidImageFolder().getAbsolutePath() + "/" + new SimpleDateFormat("yyyyMM_dd-HHmmss").format(new Date()) + "cameraRecorder.png";
    Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();

    Bitmap bm = vv.getBitmap();
    if(bm == null)
    Log.e(TAG,"bitmap is null");

    OutputStream fout = null;
    File imageFile = new File(mPath);

    try {
    fout = new FileOutputStream(imageFile);
    bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
    fout.flush();
    fout.close();
    } catch (FileNotFoundException e) {
    Log.e(TAG, "FileNotFoundException");
    e.printStackTrace();
    } catch (IOException e) {
    Log.e(TAG, "IOException");
    e.printStackTrace();
    }
    }


    But the screenshot does not appear in the gallery and knocks out an error.
    That's what produces in Logcat



     E/TextureViewActivity: FileNotFoundException
    11-14 15:25:09.961 4143-4143/com. W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/201811_14-152509cameraRecorder.png: open failed: ENOENT (No such file or directory)
    11-14 15:25:09.971 4143-4143/com. W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
    11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
    11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
    11-14 15:25:09.971 4143-4143/com. W/System.err: at com.
    camera.VideoProcessor.getBitmap(VideoProcessor.java:245)
    11-14 15:25:09.971 4143-4143/com. W/System.err: at com.camera.VideoProcessor.onClick(VideoProcessor.java:369)



    Here on what part of the code knocks an error




    at com.camera.VideoProcessor.getBitmap(VideoProcessor.java:247)  ->  fout = new FileOutputStream(imageFile);


    I would be very grateful for your help)










    share|improve this question



























      0












      0








      0








      Good afternoon, in my application I shoot video with a mobile camera, then I launch this video thanks



      @Override
      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
      {
      Surface s = new Surface(surface);

      try
      {
      mp = new MediaPlayer();
      mp.setDataSource(getVideoFilePath());
      mp.setSurface(s);
      mp.prepare();

      mp.setOnBufferingUpdateListener(this);
      mp.setOnCompletionListener(this);
      mp.setOnPreparedListener(this);
      mp.setOnVideoSizeChangedListener(this);

      mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
      setPreviewSize(true);
      mp.start();
      }
      catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }


      I implemented a method that takes a screenshot and saves it to the gallery,



        public void getBitmap(TextureView vv)
      {
      String mPath = getAndroidImageFolder().getAbsolutePath() + "/" + new SimpleDateFormat("yyyyMM_dd-HHmmss").format(new Date()) + "cameraRecorder.png";
      Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();

      Bitmap bm = vv.getBitmap();
      if(bm == null)
      Log.e(TAG,"bitmap is null");

      OutputStream fout = null;
      File imageFile = new File(mPath);

      try {
      fout = new FileOutputStream(imageFile);
      bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
      fout.flush();
      fout.close();
      } catch (FileNotFoundException e) {
      Log.e(TAG, "FileNotFoundException");
      e.printStackTrace();
      } catch (IOException e) {
      Log.e(TAG, "IOException");
      e.printStackTrace();
      }
      }


      But the screenshot does not appear in the gallery and knocks out an error.
      That's what produces in Logcat



       E/TextureViewActivity: FileNotFoundException
      11-14 15:25:09.961 4143-4143/com. W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/201811_14-152509cameraRecorder.png: open failed: ENOENT (No such file or directory)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at com.
      camera.VideoProcessor.getBitmap(VideoProcessor.java:245)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at com.camera.VideoProcessor.onClick(VideoProcessor.java:369)



      Here on what part of the code knocks an error




      at com.camera.VideoProcessor.getBitmap(VideoProcessor.java:247)  ->  fout = new FileOutputStream(imageFile);


      I would be very grateful for your help)










      share|improve this question
















      Good afternoon, in my application I shoot video with a mobile camera, then I launch this video thanks



      @Override
      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
      {
      Surface s = new Surface(surface);

      try
      {
      mp = new MediaPlayer();
      mp.setDataSource(getVideoFilePath());
      mp.setSurface(s);
      mp.prepare();

      mp.setOnBufferingUpdateListener(this);
      mp.setOnCompletionListener(this);
      mp.setOnPreparedListener(this);
      mp.setOnVideoSizeChangedListener(this);

      mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
      setPreviewSize(true);
      mp.start();
      }
      catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }


      I implemented a method that takes a screenshot and saves it to the gallery,



        public void getBitmap(TextureView vv)
      {
      String mPath = getAndroidImageFolder().getAbsolutePath() + "/" + new SimpleDateFormat("yyyyMM_dd-HHmmss").format(new Date()) + "cameraRecorder.png";
      Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();

      Bitmap bm = vv.getBitmap();
      if(bm == null)
      Log.e(TAG,"bitmap is null");

      OutputStream fout = null;
      File imageFile = new File(mPath);

      try {
      fout = new FileOutputStream(imageFile);
      bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
      fout.flush();
      fout.close();
      } catch (FileNotFoundException e) {
      Log.e(TAG, "FileNotFoundException");
      e.printStackTrace();
      } catch (IOException e) {
      Log.e(TAG, "IOException");
      e.printStackTrace();
      }
      }


      But the screenshot does not appear in the gallery and knocks out an error.
      That's what produces in Logcat



       E/TextureViewActivity: FileNotFoundException
      11-14 15:25:09.961 4143-4143/com. W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/201811_14-152509cameraRecorder.png: open failed: ENOENT (No such file or directory)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at com.
      camera.VideoProcessor.getBitmap(VideoProcessor.java:245)
      11-14 15:25:09.971 4143-4143/com. W/System.err: at com.camera.VideoProcessor.onClick(VideoProcessor.java:369)



      Here on what part of the code knocks an error




      at com.camera.VideoProcessor.getBitmap(VideoProcessor.java:247)  ->  fout = new FileOutputStream(imageFile);


      I would be very grateful for your help)







      android file screenshot fileoutputstream






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 16:39









      Fantômas

      32.6k156389




      32.6k156389










      asked Nov 14 '18 at 15:01









      fcbarcafcfcbarcafc

      14




      14
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It sounds like you don't have the right permissions.



          Add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to AndroidManifest.xml if it isn't already there.






          share|improve this answer
























          • it was added from the very beginning, unfortunately, this is not a problem))

            – fcbarcafc
            Nov 14 '18 at 17:56













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303123%2fgetbitmap-method-does-not-save-the-screenshot%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It sounds like you don't have the right permissions.



          Add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to AndroidManifest.xml if it isn't already there.






          share|improve this answer
























          • it was added from the very beginning, unfortunately, this is not a problem))

            – fcbarcafc
            Nov 14 '18 at 17:56


















          0














          It sounds like you don't have the right permissions.



          Add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to AndroidManifest.xml if it isn't already there.






          share|improve this answer
























          • it was added from the very beginning, unfortunately, this is not a problem))

            – fcbarcafc
            Nov 14 '18 at 17:56
















          0












          0








          0







          It sounds like you don't have the right permissions.



          Add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to AndroidManifest.xml if it isn't already there.






          share|improve this answer













          It sounds like you don't have the right permissions.



          Add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to AndroidManifest.xml if it isn't already there.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 16:02









          LadyCailinLadyCailin

          598418




          598418













          • it was added from the very beginning, unfortunately, this is not a problem))

            – fcbarcafc
            Nov 14 '18 at 17:56





















          • it was added from the very beginning, unfortunately, this is not a problem))

            – fcbarcafc
            Nov 14 '18 at 17:56



















          it was added from the very beginning, unfortunately, this is not a problem))

          – fcbarcafc
          Nov 14 '18 at 17:56







          it was added from the very beginning, unfortunately, this is not a problem))

          – fcbarcafc
          Nov 14 '18 at 17:56






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303123%2fgetbitmap-method-does-not-save-the-screenshot%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."