RhomburVernius
RhomburVernius

Reputation: 2250

Why doesn't my image show up at the correct size?

I have 2 images on disk in my resources folder: [email protected] and [email protected]. The 3x one is 64x64, the 2x is 32x32. I was having some issues with using a button and setting its image, where the button size was smaller than the image size. So I decided I'll just use an image and add a tap gesture instead. Problem is I can't for the life of me figure out how to get the image to just show up at its normal size. It keeps resizing the image to 16x16. All I'm doing is:

var imageSend = new Image {Source = "send"}

I add the image to my relative layout, only setting an X/Y constraint. The image shows up as 16x16. I set a breakpoint in the Y constraint and just for fun looked at the result of a call to .Measure for the image: it comes back as 16x16. I tried setting the requested width/height to 32 but there's 2 problems with that:

  1. It doesn't work. The image appears as the same size and the size that appears from a call to Measure for some odd reason shows up as 32x16
  2. I don't want to hard code a size. The image should be the size of its natural size.

How the heck do I display an image at its original size?

Edit: just for fun I doubled the image sizes to be 128x128 and 64x64. Now the image shows up as 32x32. Why? I don't have any image at that size.

Upvotes: 0

Views: 203

Answers (1)

pinedax
pinedax

Reputation: 9346

Your issue, which is not really an issue, is related to how iOS handles the image resources.

@2x and @3x means to iOS that these are images 2x (2 times) and 3x (3 times) the size of your original image hence when you say [email protected] and its size is 32x32 iOS will calculate that original size as 16x16.

Not so long ago you would have needed 3 images:

@1x original size which @2x double the size of the original @3x 3 times the size of the original

Even though you are not using the @1x image in your project you need to use its size as the base since this is what iOS will do.

Ex: You want an image with size of 45x90 your @2x and @3x images will have sizes of 90x180 and 135x270 respectively.

So as you found out making the image double the size fixed your issue.

More about iOS image resolutions here

Hope this helps.-

Upvotes: 1

Related Questions