Bug 10117 - Binding missing for resizableImageWithCapInsets:resizingMode:
Summary: Binding missing for resizableImageWithCapInsets:resizingMode:
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-02-07 05:10 UTC by Mark Daniel
Modified: 2013-02-12 05:22 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Mark Daniel 2013-02-07 05:10:23 UTC
There is a native method on UIImage called

resizableImageWithCapInsets:resizingMode: 

But the binding for UIImage only has 

UIImage CreateResizableImage (UIEdgeInsets capInsets)

I was expecting an overload 

UIImage CreateResizableImage (UIEdgeInsets capInsets, UIImageResizingMode resizingMode)

But there is none. 

There is a constructor for (UIEdgeInsets capInsets, UIImageResizingMode resizingMode) but it's no use because UIImage is immutable and there is no way to get data into it.
Comment 1 Miguel de Icaza [MSFT] 2013-02-12 00:18:37 UTC
There was a bug in the CreateResizableImage binding, you can for now do:

(UIImage) Runtime.GetNSObject (someImage.CreateResizableImage (capInsets, resizingMode))

For now, the next version will fix the return value from IntPtr to UIImage.
Comment 2 Miguel de Icaza [MSFT] 2013-02-12 00:20:34 UTC
The workaround wont work, I was looking at our local fix.
Comment 3 Mark Daniel 2013-02-12 05:22:50 UTC
The work around I am using is

  /// <summary>
    /// Extensions to the UIImage class
    /// </summary>
    /// <remarks>Adds a method that exists in native but is missing from the MT bindings</remarks>
    public static class UIImageExtensions
    {
        

        /// <summary>
        /// Creates a new resizeable image from this one. Allow you to specify the fixed regions and the resizing mode.
        /// </summary>
        /// <returns>The resizable image.</returns>
        /// <param name="image">Image.</param>
        /// <param name="capInsets">Cap insets.</param>
        /// <param name="resizingMode">Resizing mode.</param>
        public static UIImage CreateResizableImage(this UIImage image, UIEdgeInsets capInsets, UIImageResizingMode resizingMode)
        {
            UIImage result;

            using (new NSAutoreleasePool ())
            {


                if (image.GetType() == typeof(UIImage))
                {
                    result = (UIImage)Runtime.GetNSObject
                        (Messaging.
                         IntPtr_objc_msgSend_UIEdgeInsets_int (image.Handle, 
                                                              new Selector("resizableImageWithCapInsets:resizingMode:").Handle, 
                                                              capInsets,
                                                              (int)resizingMode));
                }
                else
                {
                    result = (UIImage)Runtime.GetNSObject
                        (Messaging.IntPtr_objc_msgSend_UIEdgeInsets_int (image.SuperHandle,
                                                                         new Selector("resizableImageWithCapInsets:resizingMode:").Handle, capInsets,
                                                                         (int)resizingMode));
                }
            }
            return result;
        }
    }