So this question has been asked before, but please read to the end before down voting since this is different.
I have a camera which takes an image in Android and then returns that image as a bitmap to be placed into an ImageView. The image that is returned comes from a class that has done some work with a UVC camera and then returns the image. So when the Activity gets the image it gets it via a callback that was registered to the interface. In any case, here is the code of the callback.
@Override
public void onCaptureComplete(final Bitmap data)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
nextButton.setVisibility(View.VISIBLE);
recaptureButton.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
imageView.setImageBitmap(data);
imageView.invalidate();
((View) mUVCCameraView).setVisibility(View.INVISIBLE);
faceController.closeCamera();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
data.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
imageData = byteArray;
}
});
}
So the first time I get the image it sets it as it was captured, but if I recapture the image in the same instance of that Activity, so a recapture, then the image just shows the first image that was captured and never the second image. If I minimise the app and open it again then it crashes and tells me it is trying to reference a Bitmap image that does not exist anymore. The actual data is that of the new image though, it is just the ImageView that refuses to update.
I also tried using an AsyncTask to do this and have the exact same result.
@Override
public void onCaptureComplete(Bitmap data)
{
new UpdateUI().execute(data);
}
public class UpdateUI extends AsyncTask<Bitmap, Void, Bitmap>
{
@Override
protected void onPreExecute()
{
}
@Override
protected Bitmap doInBackground(Bitmap... params)
{
return params[0];
}
@Override
protected void onPostExecute(Bitmap data)
{
nextButton.setVisibility(View.VISIBLE);
recaptureButton.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
imageView.setImageBitmap(data);
imageView.invalidate();
((View) mUVCCameraView).setVisibility(View.INVISIBLE);
faceController.closeCamera();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
data.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
imageData = byteArray;
}
}
So I was thinking I can try changing the Activity to use a fragment and see if that works or perhaps using a BroadCast receiver, but I am not sure why this is happening.
I thought that it might have to do with the face that the data is coming from a Static instance from the class/interface section of code but I have tried so many things and it just won't update.
Let me know if any more code is needed.
Thanks, Wihan
EDIT: The imageView.setVisibility happens but not the changing of the bitmap image.