Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] calculate image size before display #73

Closed
trumdongnat opened this issue Sep 22, 2020 · 3 comments
Closed

[Question] calculate image size before display #73

trumdongnat opened this issue Sep 22, 2020 · 3 comments

Comments

@trumdongnat
Copy link

I am trying to show list of image from urls in collection view(one column). Image width is fit to screen width and the height is calculated base on the width and the aspect is preserved.

HeightRequest=screen width * original image height / original image width

Please let me ask 2 questions

  1. How to get the original size of image.
  2. How to set the HeightRequest before render/decode the image.
@jonathanpeppers
Copy link
Owner

Do you even need to know the size of the image here?

Can you just set:

  • WidthRequest to screen width
  • Center the image horizontally/vertically (need both in case the image is smaller than the screen)

@trumdongnat
Copy link
Author

@jonathanpeppers sorry, the solution is not working for me.
I tried both Center and CenterAndExpand. If I don't set the HeightRequest, the height of Image will be about 1, 2 px. I think when the collection view calculate the size of Image, because the Image is still not loaded, the Image require only 1 px. And its size is not update again after finish loading.
So I think I have to set HeightRequest manually when It loaded.

@trumdongnat
Copy link
Author

Update.
I found solution now.

  1. How to get the original size of image.
    I follow this guide
    https://stackoverflow.com/questions/47827015/how-to-get-original-image-size-by-using-glide-on-android
  2. How to set the HeightRequest before render/decode the image.
    I create ImageSizeContainer to contain the image size. When I get the original size, I add it to container.
    The container will raise the event with url and original size of image.
    The Image will listen the event and update HeightRequest.
    My list can scroll smoothly now.
    Thank you very for this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants