Android Question ImageView takes a long time to display

biometrics

Active Member
Licensed User
In fact doesn't really look like you need the code after .ImageFile. Still the same result though:

B4X:
Sub Activity_Resume
   ScaleImageView1.ImageFile = Starter.ViewerFolder & Starter.ViewerFilename
End Sub
 

agraham

Expert
Licensed User
A value of 0 for ViewerZoom is not valid - it means infinitely small. It will be replaced by whatever the ScaleImageView thinks is its minimum zoom value which is the value it thinks will cause the image to fill the view. It normally will not display an image smaller than that.

My guess is that
B4X:
  Dim jo As JavaObject = Activity
  jo.RunMethod("setSystemUiVisibility", Array As Object(5894))
  Activity.Width = -1
  Activity.Height = -1
is confusing things. Why it is there when you have #FullScreen: true in the Activity attributes?
 

biometrics

Active Member
Licensed User
A value of 0 for ViewerZoom is not valid - it means infinitely small. It will be replaced by whatever the ScaleImageView thinks is its minimum zoom value which is the value it thinks will cause the image to fill the view. It normally will not display an image smaller than that.

My guess is that
B4X:
  Dim jo As JavaObject = Activity
  jo.RunMethod("setSystemUiVisibility", Array As Object(5894))
  Activity.Width = -1
  Activity.Height = -1
is confusing things. Why it is there when you have #FullScreen: true in the Activity attributes?
This version of Android doesn't go full screen with #FullScreen, I need to do

B4X:
  Dim jo As JavaObject = Activity
  jo.RunMethod("setSystemUiVisibility", Array As Object(5894))
to remove the toolbar and

B4X:
  Activity.Width = -1
  Activity.Height = -1
for the Activity to use that toolbar space. I work with a wide variety of Android devices and they all need some kind of work around. I've been using this code on certain devices for ages. It is not the issue.

Fact is when using the Designer ViewerZoom works and I can zoom it up and down. When using code it has no effect, no matter the value.
 

biometrics

Active Member
Licensed User
A value of 0 for ViewerZoom is not valid - it means infinitely small. It will be replaced by whatever the ScaleImageView thinks is its minimum zoom value which is the value it thinks will cause the image to fill the view. It normally will not display an image smaller than that.
What value must ViewerZoom be for a full screen image as your example has a value of 2? I thought 0 might mean, no zoom.

Edit: through experimentation it seems 0.66 is full screen using the Designer. Any less and it remains full screen.
 
Last edited:

biometrics

Active Member
Licensed User
@agraham

Interestingly, logging the ScaleImageView1.Scale after loading the image

With code: .Scale = 0.39025938510894775
With Designer: Scale = .0.6666666865348816

It's set to 0.66 in Starter.
 

agraham

Expert
Licensed User
I've been using this code on certain devices for ages. It is not the issue.
It certainly is an issue on the Huawei Y7 with Android 8.0 I am using at the moment. That code reduces the vertical size of the Activity and leaves a blank space at the bottom.

The ViewerZoom value is the scale of the original image so the value to fill the ScaleImageView will depend upon both the size of the ScaleImageView and the size of the original image. A value of 1 will display the image at its normal size with the displayed area being whatever will fit in the ScaleImageView.
 

biometrics

Active Member
Licensed User
The ViewerZoom value is the scale of the original image so the value to fill the ScaleImageView will depend upon both the size of the ScaleImageView and the size of the original image. A value of 1 will display the image at its normal size with the displayed area being whatever will fit in the ScaleImageView.
I can confirm changing the ViewerZoom works when using the Designer and does not when using code.

Do you not see the same issue?
 

biometrics

Active Member
Licensed User
It certainly is an issue on the Huawei Y7 with Android 8.0 I am using at the moment. That code reduces the vertical size of the Activity and leaves a blank space at the bottom.
As mentioned, we need to do workarounds on every device we use, and we've used many. We don't write for phones but for unattended devices like:

http://www.giadatech.com/index/product/detail/aid/441.html

In the case of this device that code is required. It has nothing to do with the problem I'm having though.
 

agraham

Expert
Licensed User
Setting ViewerZoom works fine for me in both Designer and code usage. Have you set ScaleImageView.MaxZoom? The default value is a modest 2 as ScaleImageView is intended for very large images and double tapping will set the zoom to either minimum or maximum. For the intended very large images a maximum zoom of more than 2 usually gives a uselessly small view of the image.

As I mentioned above the smallest scale displayable should fill the view in one or other of the width and the height. If you are getting images smaller than that I cannot ascribe it to anything other than a feature of that particular device.
 

biometrics

Active Member
Licensed User
Setting ViewerZoom works fine for me in both Designer and code usage. Have you set ScaleImageView.MaxZoom? The default value is a modest 2 as ScaleImageView is intended for very large images and double tapping will set the zoom to either minimum or maximum. For the intended very large images a maximum zoom of more than 2 usually gives a uselessly small view of the image.

As I mentioned above the smallest scale displayable should fill the view in one or other of the width and the height. If you are getting images smaller than that I cannot ascribe it to anything other than a feature of that particular device.
Ah ha. Setting .MaxZoom to 10 allows me to increase the zoom in code. But in the mean time I have found a workaround for my origin problem...

@Erel Thought you'd like to know:

I have found a work around.

I load the image like this:

B4X:
libImage.Visible = True
libImage.Bitmap = LoadBitmap(...)
Adding these two lines of code makes it display during runtime:

B4X:
libImage.SetVisibleAnimated(0, True)
Sleep(0)
Yay!

I thought I'll access every property/function to see if I can trigger some other code path to force a redraw and after trying everything and observing that I can make the image show it was a matter of elimination to get to those two lines. :)
 
Top