Error while exiting the Camera2BasicFragment (Android custom camera using Camera2 API) to display captured image in next activity The Next CEO of Stack OverflowCapture Image from Camera and Display in ActivityCapture multiple images from cameraIs it possible to crop an image captured from the Camera on Android without returning to the app?Android: Crop image and Displaying it on ImageViewAndroid Custom Camera - Crop image inside RectangleImage captured by camera is not savingCapture image using dynamic co-ordinates through the cameraPassing captured Image from Camera2 Api to another ActivityAndroid Camera 2: ImageReader's Images Have no Stride ValuesHow do I safely exit the Android Camera2BasicFragment and display the captured image in the next activity?

Does int main() need a declaration on C++?

How to monitor a big program?

Why did the Drakh emissary look so blurred in S04:E11 "Lines of Communication"?

May one celebrate April fools day?

How can the PCs determine if an item is a phylactery?

Ising model simulation

Buck converter MOS Drive resulting in overheat

Is there such a thing as a proper verb, like a proper noun?

Creating a script with console commands

Migrated 2013 workflows are not working in new server

What is Decreasing Arithmetic progression?

How to externalize TikZ pictures

Why did early computer designers eschew integers?

Incomplete cube

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

Compensation for working overtime on Saturdays

Prodigo = pro + ago?

How do I secure a TV wall mount?

Can you teleport closer to a creature you are Frightened of?

Informing employers about my unwillingness to take work laptop home

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

How to pronounce fünf in 45

hook-length formula: "Fibonaccized"



Error while exiting the Camera2BasicFragment (Android custom camera using Camera2 API) to display captured image in next activity



The Next CEO of Stack OverflowCapture Image from Camera and Display in ActivityCapture multiple images from cameraIs it possible to crop an image captured from the Camera on Android without returning to the app?Android: Crop image and Displaying it on ImageViewAndroid Custom Camera - Crop image inside RectangleImage captured by camera is not savingCapture image using dynamic co-ordinates through the cameraPassing captured Image from Camera2 Api to another ActivityAndroid Camera 2: ImageReader's Images Have no Stride ValuesHow do I safely exit the Android Camera2BasicFragment and display the captured image in the next activity?










0















I've used the sample code from Google to implement a custom camera using Camera2 API. I want to display the captured image in the next activity.



Camera2Basic sample code



However, I'm unable to safely exit the Camera2BasicFragment and start the next activity to display the captured image.



This is the code where I'm trying to start the next activity:



private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener()

@Override
public void onImageAvailable(ImageReader reader)
mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));

startActivity(new Intent(getActivity(), DisplayImage.class));


;


This is the function which saves the image and crops it. I'm not sure if the cropping is right. I just want to be able to display the image in the next activity first. The camera must be working fine when I return for capturing more images later.



 private class ImageSaver implements Runnable 

/**
* The JPEG image
*/
private final Image mImage;
/**
* The file we save the image into.
*/
private final File mFile;

ImageSaver(Image image, File file)
mImage = image;
mFile = file;


@Override
public void run()
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
FileOutputStream output = null;
try
output = new FileOutputStream(mFile);
output.write(bytes);
catch (IOException e)
e.printStackTrace();
finally
mImage.close();
if (null != output)
try
output.close();
catch (IOException e)
e.printStackTrace();




capturedImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

int width = linearLayout.getWidth();
int height = linearLayout.getHeight();

int left = width/6;
int top = height/8;

croppedImage = Bitmap.createBitmap(capturedImage, left, top, 5*(width/6), 2*(height/3));













share|improve this question


























    0















    I've used the sample code from Google to implement a custom camera using Camera2 API. I want to display the captured image in the next activity.



    Camera2Basic sample code



    However, I'm unable to safely exit the Camera2BasicFragment and start the next activity to display the captured image.



    This is the code where I'm trying to start the next activity:



    private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
    = new ImageReader.OnImageAvailableListener()

    @Override
    public void onImageAvailable(ImageReader reader)
    mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));

    startActivity(new Intent(getActivity(), DisplayImage.class));


    ;


    This is the function which saves the image and crops it. I'm not sure if the cropping is right. I just want to be able to display the image in the next activity first. The camera must be working fine when I return for capturing more images later.



     private class ImageSaver implements Runnable 

    /**
    * The JPEG image
    */
    private final Image mImage;
    /**
    * The file we save the image into.
    */
    private final File mFile;

    ImageSaver(Image image, File file)
    mImage = image;
    mFile = file;


    @Override
    public void run()
    ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
    byte[] bytes = new byte[buffer.remaining()];
    buffer.get(bytes);
    FileOutputStream output = null;
    try
    output = new FileOutputStream(mFile);
    output.write(bytes);
    catch (IOException e)
    e.printStackTrace();
    finally
    mImage.close();
    if (null != output)
    try
    output.close();
    catch (IOException e)
    e.printStackTrace();




    capturedImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

    int width = linearLayout.getWidth();
    int height = linearLayout.getHeight();

    int left = width/6;
    int top = height/8;

    croppedImage = Bitmap.createBitmap(capturedImage, left, top, 5*(width/6), 2*(height/3));













    share|improve this question
























      0












      0








      0








      I've used the sample code from Google to implement a custom camera using Camera2 API. I want to display the captured image in the next activity.



      Camera2Basic sample code



      However, I'm unable to safely exit the Camera2BasicFragment and start the next activity to display the captured image.



      This is the code where I'm trying to start the next activity:



      private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
      = new ImageReader.OnImageAvailableListener()

      @Override
      public void onImageAvailable(ImageReader reader)
      mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));

      startActivity(new Intent(getActivity(), DisplayImage.class));


      ;


      This is the function which saves the image and crops it. I'm not sure if the cropping is right. I just want to be able to display the image in the next activity first. The camera must be working fine when I return for capturing more images later.



       private class ImageSaver implements Runnable 

      /**
      * The JPEG image
      */
      private final Image mImage;
      /**
      * The file we save the image into.
      */
      private final File mFile;

      ImageSaver(Image image, File file)
      mImage = image;
      mFile = file;


      @Override
      public void run()
      ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
      byte[] bytes = new byte[buffer.remaining()];
      buffer.get(bytes);
      FileOutputStream output = null;
      try
      output = new FileOutputStream(mFile);
      output.write(bytes);
      catch (IOException e)
      e.printStackTrace();
      finally
      mImage.close();
      if (null != output)
      try
      output.close();
      catch (IOException e)
      e.printStackTrace();




      capturedImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

      int width = linearLayout.getWidth();
      int height = linearLayout.getHeight();

      int left = width/6;
      int top = height/8;

      croppedImage = Bitmap.createBitmap(capturedImage, left, top, 5*(width/6), 2*(height/3));













      share|improve this question














      I've used the sample code from Google to implement a custom camera using Camera2 API. I want to display the captured image in the next activity.



      Camera2Basic sample code



      However, I'm unable to safely exit the Camera2BasicFragment and start the next activity to display the captured image.



      This is the code where I'm trying to start the next activity:



      private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
      = new ImageReader.OnImageAvailableListener()

      @Override
      public void onImageAvailable(ImageReader reader)
      mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));

      startActivity(new Intent(getActivity(), DisplayImage.class));


      ;


      This is the function which saves the image and crops it. I'm not sure if the cropping is right. I just want to be able to display the image in the next activity first. The camera must be working fine when I return for capturing more images later.



       private class ImageSaver implements Runnable 

      /**
      * The JPEG image
      */
      private final Image mImage;
      /**
      * The file we save the image into.
      */
      private final File mFile;

      ImageSaver(Image image, File file)
      mImage = image;
      mFile = file;


      @Override
      public void run()
      ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
      byte[] bytes = new byte[buffer.remaining()];
      buffer.get(bytes);
      FileOutputStream output = null;
      try
      output = new FileOutputStream(mFile);
      output.write(bytes);
      catch (IOException e)
      e.printStackTrace();
      finally
      mImage.close();
      if (null != output)
      try
      output.close();
      catch (IOException e)
      e.printStackTrace();




      capturedImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

      int width = linearLayout.getWidth();
      int height = linearLayout.getHeight();

      int left = width/6;
      int top = height/8;

      croppedImage = Bitmap.createBitmap(capturedImage, left, top, 5*(width/6), 2*(height/3));










      android android-intent android-camera2 android-image-capture






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 18:43









      VSKVSK

      5919




      5919






















          0






          active

          oldest

          votes












          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%2f55050762%2ferror-while-exiting-the-camera2basicfragment-android-custom-camera-using-camera%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f55050762%2ferror-while-exiting-the-camera2basicfragment-android-custom-camera-using-camera%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

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович