コード例 #1
0
        private void _handleButtonSaveClicked()
        {
            var    bmp     = Bitmap.CreateBitmap(dstBmp);
            Canvas canvas  = new Canvas(bmp);
            var    logoBmp = BitmapFactory.DecodeResource(Resources, Resource.Drawable.logo_horizon5);

            var compassView = new CompassView(ApplicationContext, null);

            compassView.Initialize(Context, false, new System.Drawing.Size(_photodata.PictureWidth, _photodata.PictureHeight));
            compassView.Layout(0, 0, _photodata.PictureWidth, _photodata.PictureHeight);
            compassView.InitializeViewDrawer(new System.Drawing.Size(dstBmp.Width, dstBmp.Height), new System.Drawing.Size(_photodata.PictureWidth, _photodata.PictureHeight));
            compassView.SetPoiViewItemList(Context.PoiData);
            compassView.SetElevationProfile(Context.ElevationProfileData);
            compassView.Draw(canvas);


            var logoWidth = Convert.ToInt32(0.2 * canvas.Width);

            canvas.DrawBitmap(logoBmp, new Rect(0, 0, logoBmp.Width, logoBmp.Height), new Rect(canvas.Width - logoWidth, canvas.Height - logoWidth * 2 / 3, canvas.Width, canvas.Height), null);
            var photoname = "export" +
                            "" + _photodata.PhotoFileName;
            var filename = System.IO.Path.Combine(ImageSaverUtils.GetPublicPhotosFileFolder(), photoname);

            if (File.Exists(filename))
            {
                AlertDialog.Builder alert = new AlertDialog.Builder(this).SetCancelable(false);
                alert.SetPositiveButton(Resources.GetText(Resource.String.Common_Yes), (senderAlert, args) =>
                {
                    File.Delete(filename);
                    var stream = new FileStream(filename, FileMode.CreateNew);
                    bmp.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                    Android.Media.MediaScannerConnection.ScanFile(Android.App.Application.Context, new string[] { filename }, null, null);
                    PopupHelper.Toast(this, Resource.String.PhotoShow_PhotoSaved);
                });
                alert.SetNegativeButton(Resources.GetText(Resource.String.Common_No), (senderAlert, args) => { });
                alert.SetMessage(Resources.GetText(Resource.String.PhotoShow_OverwriteQuestion));
                var answer = alert.Show();
            }
            else
            {
                var stream = new FileStream(filename, FileMode.CreateNew);
                bmp.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                Android.Media.MediaScannerConnection.ScanFile(Android.App.Application.Context, new string[] { filename }, null, null);
                PopupHelper.Toast(this, Resource.String.PhotoShow_PhotoSaved);
            }
        }
コード例 #2
0
        private void _handleButtonShareClicked()
        {
            var    bmp     = Bitmap.CreateBitmap(dstBmp);
            Canvas canvas  = new Canvas(bmp);
            var    logoBmp = BitmapFactory.DecodeResource(Resources, Resource.Drawable.logo_horizon5);

            var compassView = new CompassView(ApplicationContext, null);

            compassView.Initialize(Context, false, new System.Drawing.Size(_photodata.PictureWidth, _photodata.PictureHeight));
            compassView.Layout(0, 0, _photodata.PictureWidth, _photodata.PictureHeight);
            compassView.InitializeViewDrawer(new System.Drawing.Size(dstBmp.Width, dstBmp.Height), new System.Drawing.Size(_photodata.PictureWidth, _photodata.PictureHeight));
            compassView.SetPoiViewItemList(Context.PoiData);
            compassView.SetElevationProfile(Context.ElevationProfileData);
            compassView.Draw(canvas);

            var logoWidth = Convert.ToInt32(0.2 * canvas.Width);

            canvas.DrawBitmap(logoBmp, new Rect(0, 0, logoBmp.Width, logoBmp.Height), new Rect(canvas.Width - logoWidth, canvas.Height - logoWidth * 2 / 3, canvas.Width, canvas.Height), null);
            //canvas.DrawBitmap(logoBmp, canvas.Width - logoBmp.Width - 40, canvas.Height - logoBmp.Height - 40, null);

            var filename = System.IO.Path.Combine(ImageSaverUtils.GetPhotosFileFolder(), "tmpHorizon.jpg");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            var stream = new FileStream(filename, FileMode.CreateNew);

            bmp.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
            Android.Media.MediaScannerConnection.ScanFile(Android.App.Application.Context, new string[] { filename }, null, null);

            var result = Share.RequestAsync(new ShareFileRequest
            {
                Title = Title,
                File  = new ShareFile(filename)
            });
        }