Hello,
*** 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:
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?
Thanks,
Barry.
Update:
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.
*** 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:
B4X:
Dim ops As OutputStream = File.OpenOutput(dir, fn, False)
bm.WriteToStream(ops, Qual, fmt)
ops.Close
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?
Thanks,
Barry.
Update:
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: