0
votes

I am trying to resize pictures using this GihHub code from Xamarin website .

The code is greyed out when I want to implement it in my Xamarin forms shared project.

It seems that :

#if __IOS__

#endif
#if __ANDROID__

#endif

does not work. I looked for many solutions and just find this one:

if (Device.RuntimePlatform == Device.iOS)
{
    // iOS
    return ResizeImageIOS(imageData, width, height);
}
else if (Device.RuntimePlatform == Device.Android)
{
    // Android
}

But the things is I cannot see how to do it because there are functions.

If you have a better solution I will take.

1

1 Answers

0
votes

You need to define IOS in your build options/conditional compilation symbols for the iOS project, and ANDROID in your build options/conditional compilation symbols for the Android project. If the code is greyed out, it means you current have neither symbol defined.

Like this

That being said, the normal way to do platform specific things is to have different code for each platform in different classes, and use DI to wire up the correct class for the current plaform.