3

I have a class which loads an image from an Embedded Resource in a referenced MonoTouch library as follows:

UIImage.FromResource (null, "Resources.Items");

If it was UIImage.FromFile ("abc.png"); and I included a file named abc@2x.png the retina image would be displayed on a compatible device.

How do I achieve the same, i.e. load a retina image, using UIImage.FromResource (null, "Resources.Items");

I cannot use UIImage.FromFile ("abc.png"); as the resource is in a referenced DLL.

Darbio
  • 11,286
  • 12
  • 60
  • 100

1 Answers1

3

It's easy to detect a retina display. From there you can load the right resource from your assembly. E.g.

UIImage.FromResource (null, (UIScreen.MainScreen.Scale > 1.0)
    ? "Resources.Items.Retina" : "Resources.Items");

Using this you can name your retina resource as you like, including using the standard @2x notation if you like it.

Community
  • 1
  • 1
poupou
  • 43,413
  • 6
  • 77
  • 174
  • I haven't tried this yet, but in order for the retina image to be displayed as a retina image, does `Resources.Items.Retina` need to be scaled by 0.5? I only ask as logically I would expect the @2x `UIImage` to show as a normal image, twice the size (e.g. 64 x 64, instead of 32 x 32). – Darbio Jan 14 '13 at 22:43
  • It depends on the context of it's use. If you're displaying it using your own code then see: http://stackoverflow.com/a/11808894/220643 If ever in doubt use the simulator (retina, 1x zoom) and any (of the multiple) tools that allow you to zoom on the screen. It will be apparent if the image is scaled (or not). – poupou Jan 15 '13 at 00:23