Exemplo n.º 1
0
        /**
         * Exports the bitmap of the current chart to the device's storage
         *
         * @return
         *
         */
        public async Task exportImage()
        {
            String APP_PATH_SD_CARD = "/xuni/samples/FlexChart/";
            var    image            = await mChart.GetImage();

            string fullPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + APP_PATH_SD_CARD;

            try
            {
                Java.IO.File dir = new Java.IO.File(fullPath);
                if (!dir.Exists())
                {
                    dir.Mkdirs();
                }

                // save image to a new file
                string name = fullPath + System.DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                System.IO.File.WriteAllBytes(name, image);

                // add index of the image to the gallery
                Intent          mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                Android.Net.Uri contentUri      = Android.Net.Uri.FromFile(new Java.IO.File(name));
                mediaScanIntent.SetData(contentUri);
                SendBroadcast(mediaScanIntent);

                Toast.MakeText(this, Resource.String.snapshotStored, ToastLength.Short).Show();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("exportImage failed: " + e.Message);
            }
        }