Image height in pixels after image is resized using maintain aspect

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

I would like to know how I can read out the image height in pixels relative to the screen.

I have an image set in the middle of the screen which has a width and height of 100%. With the setting Maintain aspect ratio.

I would like to know how I can know the current height in pixels?

Hi ,

As of now, we do not have such functionality where we can convert dp to px. We have an existing FTR for the same. Request to create a Zendesk ticket to get more updates on the FTR.

To achieve your requirement, you need to write the FFI/NFI.

The below code snippet helps you to convert dp to px and vice versa.

public int dpToPx(int dp) {

DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();

return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));

}

public int pxToDp(int px) {

DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();

return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));

}

Whatever the px you received as the return, you need to below step to get the percentages.

If the parent container Width/Height is in px.

Percentage of widget = (Pixel of widget container/ Pixel of Parent Container) * 100.

Note: The widgets height/width depends on the parent container.

Ok thanks, I will try it out. You don't happen to have an example app for this?

Hi ,

As of now, we do not have any example on that. Did my response help you? If yes, make sure you click [Select as Best] under the response to close out the post.