Android Question ImageView resize and invalidate

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I am displaying an image within an ImageView on a Panel. The ImageView gravity is "Fill". The image within the ImageView starts out as a square "noise" pattern. I then resize the image view and display a bitmap file from the camera (it turns out the aspect ratio of the bitmap is narrower than the original image). I resize and reposition the ImageView, but this does not happen properly. There seem to be artifacts left over from the original image within the ImageView which are not invalidated, erased, or redrawn properly.

I have attached pictures which illustrate this issue. The first picture shows the initial square noise pattern. The second picture shows the result of resizing the ImageView and setting the bitmap to a picture file (from the camera). The resized Image View becomes narrower and is moved to the right in order to center on the screen. The new bitmap is aligned to the left side of the ImageView, but the right side of the Image View shows the previous noise bitmap in an area which should no longer be displayed within the resized ImageView.

I have tried many different things, including: invalidating the ImageView and/or parent panel, calling DoEvents, resetting the color of the parent panel to white hoping this will force a refresh of the entire panel. Nothing seems to work.

Any ideas how to get the Image View to redraw correctly and have the parent panel erase the background which is uncovered by the resized Image View?

Thanks,
Barry.
 

Attachments

  • img1.jpg
    img1.jpg
    52.3 KB · Views: 319
  • img2.jpg
    img2.jpg
    52 KB · Views: 359

canalrun

Well-Known Member
Licensed User
Longtime User
Any ideas how to get the Image View to redraw correctly and have the parent panel erase the background which is uncovered by the resized Image View?

I think I have solved the problem. In the same subroutine that resizes the ImageView I have a single DoEvents followed by a panel.color = colors.white.

My theory (right up there with the flat Earth theory) is that Android requires time in its processing loop to affect the ImageView changes (the DoEvents) which it may not get since the new bitmap has probably already arrived (in a NewData event). By setting the panel color I force a refresh of the entire panel which erases the artifact left from the previous bitmap.

Anyway, it seems to work.

Barry.
 
Upvote 0
Top