Retina graphics issue

nodoidnodoid GBMember, Beta ✭✭✭

Hi,

I have my graphics stored in a directory called graphics. In there I have say "hello.png" and "[email protected]". When I create my UI, I create the images on the tabbaritems in a pretty standard way and using UIImage.FromFile(...) to pull in the graphics.

This won't pull in the retina graphics, so I'm wondering if there is a way to determine if the phone is retina or not and then explicitly specify which graphics set to use.

Any advice here?

Paul

Posts

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @nodoid,

    You can use UIScreen.MainScreen.Scale and check if its 2.0. That would be retina. 1.0 would not be.

    Can't you use UIImage.FromBundle("graphics/hello.png")?

  • Bob_ReckBob_Reck USMember ✭✭✭

    @nodoid,

    Actually, that will pull the retina images if they are there. iOS knows to look for a retina image if the current device supports it.

    Are you sure you're not seeing the retina versions or were you just assuming that it isn't? Just curious.

    Bob

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    I just check some code, and I use UIImage.FromFile as well and it pulls in retina images.

  • nodoidnodoid GBMember, Beta ✭✭✭

    @john - do I need to alter the filename using FromFile to include the @2x part?
    @bob - not seeing nice high res graphics is all

  • Bob_ReckBob_Reck USMember ✭✭✭

    You shouldn't have to change the name or anything. The OS takes care of that. Are you running in the retina simulator or on a retina device? If so, then they should be displaying.

    Bob

  • nodoidnodoid GBMember, Beta ✭✭✭

    Tried on both

  • GrantCauseGrantCause AUMember ✭✭

    Got this from the MWC2012 demo app:

    using MonoTouch.UIKit;
    using MonoTouch.ObjCRuntime;

        public static bool IsPhone {
            get {
                return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone;
            }
        }
        public static bool IsPad {
            get {
                return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad;
            }
        }
    
        public static bool HasRetina {
            get {
                if (MonoTouch.UIKit.UIScreen.MainScreen.RespondsToSelector(new Selector("scale")))
                    return (MonoTouch.UIKit.UIScreen.MainScreen.Scale == 2.0);
                else
                    return false;
            }
        }
    

    Hope it helps.

  • nodoidnodoid GBMember, Beta ✭✭✭

    Thanks :)

  • RichardHopkinsRichardHopkins JPMember, University ✭✭✭
    edited November 2013

    I realise this may not be true in all cases, but I think the need for @2x images is sometimes overstated. I've built most of my apps using only retina resolution images without the @2x name. In the majority of cases providing you set frame and/or scale correctly, the earlier phones seem to cope fine with it. I think sometimes people end up using two images when they could easily just use one, and scale it to half size. Which presumably makes app sizes larger than they need to be (unless Apple have some magic at their end which strips out images that aren't needed). Added to which, just dealing with 1 set of images is a lot easier, especially when things need to be updated or replaced.

  • MagooCMagooC AUMember

    Doesn't scaling during runtime hurt performance hence the reason to provide correctly scaled image?

  • RichardHopkinsRichardHopkins JPMember, University ✭✭✭
    edited November 2013

    If you're doing something that involves a lot of heavy image manipulation (perhaps animations) sure, it could. If you're talking about the background for a button, then no, I've not found it to be a problem.

    To be honest though it often becomes a moot point (at least in my line of work - others may vary). Once you start doing animations with larger images, theres a high chance they're going to suck on non-retina phones anyway, whatever you do, so there's not always much point in supporting them.

Sign In or Register to comment.