ComponentOne Xamarin.iOS Documentation
Controls / Gauge / Features / Export Image
In This Topic
    Export Image
    In This Topic

    C1Gauge allows you to export your gauge in the form of an image and save it to the Camera Roll of your iOS device, or you can select your preferred location as per the requirement. It works exactly how you take a screen shot on your iPhones and iPads. The example below adds a snapshot button on the top of the XuniGauge. Users can tap the button to save the chart in the gallery.

    In Code

    C#
    Copy Code
    using C1.iOS.Core;
    using C1.iOS.Gauge;
    using CoreGraphics;
    using Foundation;
    using System;
    using UIKit;
    namespace GaugeTest
    {
        public partial class ViewController : UIViewController
        {
            C1RadialGauge RadialGauge = new C1RadialGauge();
            public ViewController(IntPtr handle) : base(handle)
            {
            }
    
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                // Perform any additional setup after loading the view, typically from a nib.
            }
    
            public override void DidReceiveMemoryWarning()
            {
                base.DidReceiveMemoryWarning();
                // Release any cached data, images, etc that aren't in use.
            }
    
            partial void DoSnapshot(UIBarButtonItem sender)
            {
                SaveImageToDisk();
            }
    
            async void SaveImageToDisk()
            {
                var gaugeImage = new UIImage(NSData.FromArray(await RadialGauge.GetImage()));
                gaugeImage.SaveToPhotosAlbum((image, error) =>
                {
                    string message, title;
    
                    if (error == null)
                    {
                        title = Foundation.NSBundle.MainBundle.LocalizedString("ImageSavedTitle", "");
                        message = Foundation.NSBundle.MainBundle.LocalizedString("ImageSavedDescription", "");
    
                    }
                    else
                    {
                        title = Foundation.NSBundle.MainBundle.LocalizedString("PermissionDenied", "");
                        message = error.Description;
                    }
    
                    UIAlertView alert = new UIAlertView(title, message, null, "OK", null);
                    alert.Show();
                });
            }
    
        }
    }