示例#1
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            sfImageEditor       = new SfImageEditor(new CGRect(View.Frame.Location.X, 60, View.Frame.Size.Width, View.Frame.Size.Height - 60));
            sfImageEditor.Image = UIImage.FromBundle("Images/ImageEditor/WhiteImage.png");
            var sampleTimer = NSTimer.CreateTimer(TimeSpan.FromSeconds(3.0), delegate
            {
                ReadFile();
                Dispose();
            });

            sampleTimer.Fire();
            sfImageEditor.ImageSaving += (sender, e) =>
            {
                e.Cancel = true;
                var    stream    = e.Stream;
                var    byteArray = ReadFully(stream);
                NSData data      = NSData.FromArray(byteArray);

                if (_model.Name == "Create New")
                {
                    var count = _collectionView.DataSource.Count;
                    SerializationModel item = new SerializationModel()
                    {
                        Name                 = itemName != "" ? itemName : ValidateName(),
                        ImageAlignment       = UIViewContentMode.Center,
                        ImageBackgroundColor = UIColor.FromRGB(255, 255, 255),
                        id        = count - 1,
                        EditsStrm = null
                    };
                    item.EditsStrm      = sfImageEditor.SaveEdits();
                    item.Image          = UIImage.LoadFromData(data);
                    item.ImageAlignment = UIViewContentMode.ScaleAspectFit;
                    _serializationViewModel.ModelCollection.Add(item);
                    EditsViewModel.EditsCollection.Add(new EditsModel()
                    {
                        Name = item.Name
                    });
                }
                else
                {
                    _model.EditsStrm      = sfImageEditor.SaveEdits();
                    _model.Image          = UIImage.LoadFromData(data);
                    _model.ImageAlignment = UIViewContentMode.ScaleAspectFit;
                }


                _collectionView.DataSource = _serializationViewModel.ModelCollection;
            };

            this.View.Add(sfImageEditor);
        }
        void Editor_ImageSaving(object sender, ImageSavingEventArgs e)
        {
            var serializedStream = editor.SaveEdits();
            var mStream          = e.Stream;

            mStream.Position = 0;
            Bitmap bitmap = BitmapFactory.DecodeStream(mStream);
            var    bitMap = bitmap; 
            if (Serialization.SelectedItem.Name != "CreateNew")

            {
                
            {
                    
 Serialization.SelectedItem.Strm = serializedStream; 
 Serialization.SelectedItem.BitMap = bitmap; 

                }
            }
            
 else
            {
                (Serialization.gridview.Adapter as ImageAdapter).mItems.Add(new Item
                {
                    Name   = name != "" ? name : ValidateName(),
                    BitMap = bitMap,
                    Strm   = serializedStream,
                    IsLongPressedEnabled = false,
                    IsItemChecked        = false,
                });
            } 
(Serialization.gridview.Adapter as ImageAdapter).NotifyDataSetChanged();
        }