Android Question JPEG to file pauses UI

Discussion in 'Android Questions' started by canalrun, Apr 14, 2015.

  1. canalrun

    canalrun Well-Known Member Licensed User


    *** see update below ***

    I'm writing a JPEG to a file during a picture_taken event. The image is 3264 x 1836, the format is JPEG.

    The file ends up being a little under 1 MB in size and requires a little under one second to write to file. Changing the image size, quality, or format is not an option – in fact the image size will only get bigger.

    I'm using the following code:

    Dim ops As OutputStream = File.OpenOutput(dir, fn, False)
      bm.WriteToStream(ops, Qual, fmt)
    The problem is writing to file pauses the UI. I have the UI updating a status label and the one second pause doesn't look very good, although it's not a biggie.

    Is there a way to move the bm.WriteToStream to execute in a background thread or something so that it doesn't pause the UI?

    I haven't found anything in the forums. Can someone point to something or suggest a solution?


    From timing measurements I see that all the time is being taken during the conversion from bitmap to JPEG, not writing the JPEG data to file.

    In my picture_taken subroutine the image data is received as a bitmap, I convert to a JPEG, then write to file.

    I believe there is a way to receive JPEG format data directly from the camera in the picture_taken subroutine. I'll have to look at that.

    My initial thought that it would speed things up by implementing the file write in the background is not correct.
    Last edited: Apr 15, 2015
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    DonManfred and lemonisdead like this.
  3. canalrun

    canalrun Well-Known Member Licensed User

    Thanks. You have me envious. I have read about your late night "going for a bike ride" posts.

    The segment of the Erie Canal (central New York State, USA. Google it, it's interesting.) near me is only about 5 miles long. I got the name CanalRun back in the early 1990s. I used to run 5K's on the Erie Canal every day. One day I was thinking, "What name should I choose? I know, CanalRun.".

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice