Example #1
0
        private void SaveDrawing()
        {
            if (Control.appearance.ToLower() == "annotate" || Control.appearance.ToLower() == "textannotate")
            {
                Bitmap Background     = ((BitmapDrawable)BackgroundImage.Drawable).Bitmap;
                Bitmap CombinedBitmap = OverlayCanvas(Background, dv.bm);

                using (var os = new FileStream(path, FileMode.Create))
                {
                    CombinedBitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, os);
                }

                //save any note that the user entered
                ExifInterface exifData = new ExifInterface(path);
                exifData.SetAttribute(ExifInterface.TagImageDescription, EditExif.Text);
                exifData.SaveAttributes();
            }
            else
            {
                using (var os = new FileStream(path, FileMode.Create))
                {
                    dv.bm.Compress(Bitmap.CompressFormat.Jpeg, 100, os);
                }
            }


            XForm.SetValue(Binding.nodeset, path);
            Finish();
        }
Example #2
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            Intent i = new Intent();

            switch (item.ItemId)
            {
            case Android.Resource.Id.Home:

                AlertDialog saveAlert = new AlertDialog.Builder(this).Create();
                saveAlert.SetTitle("Warning");
                saveAlert.SetMessage("Do you wish to save the drawing?");
                saveAlert.SetButton("Save", delegate
                {
                    SaveDrawing();
                    i.SetData(Android.Net.Uri.FromFile(new Java.IO.File(path)));
                    SetResult(Result.Ok, i);
                    WidgetHelper.activity.FireFormChangeEvent(v);

                    Finish();
                });

                saveAlert.SetButton2("Discard", delegate
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        File.Delete(path);
                    }
                    if (dv != null)
                    {
                        dv.ClearCanvas();
                        dv = null;
                    }
                    SetResult(Result.Canceled);
                    XForm.SetValue(Binding.nodeset, "");
                    Finish();
                });
                saveAlert.Show();

                return(true);

            case Resource.Id.menu_save:
                //overlay the two bitmaps together



                i.SetData(Android.Net.Uri.FromFile(new Java.IO.File(path)));
                SetResult(Result.Ok, i);
                SaveDrawing();
                WidgetHelper.activity.FireFormChangeEvent(v);
                return(true);

            //reset the item and canvas
            case Resource.Id.menu_delete:
                AlertDialog alert = new AlertDialog.Builder(this).Create();
                alert.SetTitle("Warning");
                alert.SetMessage("Do you want to delete the annotated image?");
                alert.SetButton("Yes", delegate
                {
                    File.Delete(path);
                    XForm.SetValue(Binding.nodeset, "");
                    BackgroundImage.SetImageBitmap(null);
                    if (dv != null)
                    {
                        dv.ClearCanvas();
                        dv = null;
                    }
                });
                alert.SetButton2("No", delegate { return; });
                alert.Show();
                return(true);

            //image picker
            case Resource.Id.menu_select:
                TakePhoto("drawing", Binding, v, WidgetHelper.activity, false);
                newPhoto = true;
                return(true);

            default:
                return(base.OnOptionsItemSelected(item));
            }
        }
Example #3
0
        //handle input of photos, either from gallery or camera
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            string    path = "";
            Bitmap    pic;
            ImageView iv = null;

            if (imageViewRow != null)
            {
                iv = (ImageView)imageViewRow.FindViewWithTag("image");
            }

            //user cancelled
            if (resultCode == Result.Canceled && requestCode != REQUEST_DRAWING)
            {
                File.Delete(photoFile.Path);
                return;
            }
            //camera
            if (requestCode == REQUEST_IMAGE_CAPTURE)
            {
                //

                GalleryAddPic();


                if (this is DrawingActivity)
                {
                    SetPic(DrawingActivity.BackgroundImage, photoUri);
                }
                else
                {
                    SetPic(iv, photoUri);
                }

                path = mCurrentPhotoPath;
            }

            //gallery
            else if (requestCode == REQUEST_GALLERY_IMAGE)
            {
                pic = MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
                using (var os = new FileStream(mCurrentPhotoPath, FileMode.Create))
                {
                    pic.Compress(Bitmap.CompressFormat.Jpeg, 100, os);
                }

                path = mCurrentPhotoPath;

                if (this is DrawingActivity)
                {
                    SetPic(DrawingActivity.BackgroundImage, data.Data);
                }
                else
                {
                    SetPic(iv, data.Data);
                }


                //iv.SetImageBitmap(imageBitmap);
            }
            //this only has a value when coming directly from the camera/gallery
            if (bindingForImage != null)
            {
                XForm.SetValue(bindingForImage.nodeset, path);
            }

            //coming back from a canvas
            if (requestCode == REQUEST_DRAWING && data != null)
            {
                iv = (ImageView)WidgetHelper.viewToPass.FindViewWithTag("image");
                iv.SetImageBitmap(BitmapHelpers.LoadAndResizeBitmap(data.Data.Path, 100, 100, this));
                //iv.SetImageBitmap(Bitmap.CreateScaledBitmap(BitmapFactory.DecodeFile(data.Data.Path), 100, 100, true));
            }

            if (this is ScrollFormActivity)
            {
                try
                {
                    _formActivity.FireFormChangeEvent(imageViewRow);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                if (showDialogAfterImageSelect)
                {
                    iv.PerformClick();
                }
            }
        }