Xamarin.iOS のドキュメント
画像のエクスポート
コントロール > Gauge > 機能 > 画像のエクスポート

C1Gauge を使用して、ゲージを画像の形式でエクスポートし、それを iOS デバイスのカメラロールに保存したり、必要に応じて好きな場所を選択して保存できます。iPhone や iPad でとるスクリーンショットとまったく同様に機能します。次の例では、スナップショットボタンを Gauge の上端に追加します。ユーザーは、ボタンをタップしてチャートをギャラリーに保存できます。

C# のコード

C#
コードのコピー
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();
            // ビューを読み込んだ後の追加セットアップを行います(通常は nib から)。
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // 使用されていないキャッシュされたデータ、イメージなどを解放します。
        }

        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();
            });
        }

    }
}