コード例 #1
0
        public static async Task <NGraphics.IImage> ToIImage(this FileImageSource src)
        {
            var handler = new FileImageSourceHandler();
            var bitmap  = await handler.LoadImageAsync(src, Forms.Context);

            return(new NGraphics.BitmapImage(bitmap));
        }
コード例 #2
0
        protected virtual async Task <UIImage> GetImage(ImageSource imageSource)
        {
            if (imageSource == null)
            {
                return(null);
            }

            UIImage image = null;

            try
            {
                var handler = new FileImageSourceHandler();
                image = await handler.LoadImageAsync(imageSource);
            }
            catch
            {
                // ignored
            }


            if (Element == null)
            {
                image?.Dispose();
                return(null);
            }

            return(image);
        }
コード例 #3
0
        /// <summary>
        /// Called when [element changed].
        /// </summary>
        /// <param name="e">The e.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <Image> e)
        {
            base.OnElementChanged(e);

            var targetImageView = this.Control;

            Bitmap image         = null;
            var    networkStatus = Reachability.InternetConnectionStatus();
            var    isReachable   = networkStatus != NetworkStatus.NotReachable;

            if (isReachable && !string.IsNullOrEmpty(WebImage.ImageUrl))
            {
                image = GetImageFromWeb(WebImage.ImageUrl);
            }
            else
            {
                if (!string.IsNullOrEmpty(WebImage.DefaultImage))
                {
                    var handler = new FileImageSourceHandler();
                    image = handler.LoadImageAsync(ImageSource.FromFile(WebImage.DefaultImage), this.Context).Result;
                }
            }

            targetImageView.SetImageBitmap(image);
        }
コード例 #4
0
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            if (e.NewElement is iOSSearchPage iosSearchPage)
            {
                this.searchController.SearchBar.Placeholder = iosSearchPage.SearchPlaceholder;

                Task.Run(async() =>
                {
                    if (iosSearchPage.ActionImage != null)
                    {
                        try
                        {
                            var handler     = new FileImageSourceHandler();
                            var actionImage = await handler.LoadImageAsync(iosSearchPage.ActionImage);

                            this.searchController.SearchBar.SetImageforSearchBarIcon(actionImage, UISearchBarIcon.Bookmark, UIControlState.Normal);
                            this.searchController.SearchBar.ShowsBookmarkButton = true;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine($"Error loading ActionImage: {ex.Message}");
                        }
                    }
                });
            }
        }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: freekdotcom/I-ACT
        public static async Task <NGraphics.IImage> ToIImage(this FileImageSource src)
        {
            var handler = new FileImageSourceHandler();
            var image   = await handler.LoadImageAsync(src);

            return(new NGraphics.CGImageImage(image.CGImage, 1));
        }
コード例 #6
0
        protected virtual async Task <Bitmap> GetBitmap(ImageSource imageSource)
        {
            if (imageSource == null)
            {
                return(null);
            }

            Bitmap bitmap = null;

            try
            {
                var handler = new FileImageSourceHandler();
                bitmap = await handler.LoadImageAsync(imageSource, Context);
            }
            catch
            {
                // ignored
            }

            if (Element == null)
            {
                bitmap?.Dispose();
                return(null);
            }

            return(bitmap);
        }
コード例 #7
0
        public MGLAnnotationImage MapView_ImageForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
                case SymbolAnnotation symbol:
                    switch (symbol.IconImage.Source)
                    {
                        case FileImageSource fileImageSource:
                            var cachedImage = mapView.DequeueReusableAnnotationImageWithIdentifier(fileImageSource.File);

                            if (cachedImage != null) return cachedImage;

                            var fileImageSourceHandler = new FileImageSourceHandler();
                            var image = fileImageSourceHandler.LoadImageAsync(fileImageSource).Result;

                            if (image == null) return null;

                            return MGLAnnotationImage.AnnotationImageWithImage(image, fileImageSource.File);
                    }
                    break;
            }

            return null;
        }
コード例 #8
0
        public async Task <IImage> GetImage(FileImageSource file, CancellationToken token)
        {
            var handler = new FileImageSourceHandler();
            var bitmap  = await handler.LoadImageAsync(file, Forms.Context, token);

            if (bitmap == null)
            {
                return(null);
            }

            var image = new BitmapImage(bitmap, _scale);

            return(image);
        }
コード例 #9
0
        public async Task <IImage> GetImage(FileImageSource file, CancellationToken token)
        {
            var handler     = new FileImageSourceHandler();
            var nativeImage = await handler.LoadImageAsync(file, token);

            if (nativeImage == null)
            {
                return(null);
            }

            var image = new CGImageImage(nativeImage.CGImage, _scale);

            return(image);
        }
コード例 #10
0
        public async static Task <SKBitmap> BitmapFromNativeFile(string fileName)
        {
            var imageSource = ImageSource.FromFile(fileName);
            IImageSourceHandler imageLoader = new FileImageSourceHandler();

#if __ANDROID__
            if (context == null)
            {
                throw new Exception("ImageLoader not initialized.");
            }
            Bitmap image = await imageLoader.LoadImageAsync(imageSource, context);

            return(image.ToSKBitmap());
#else
            UIImage image = await imageLoader.LoadImageAsync(imageSource);

            return(image.ToSKBitmap());

            //fix the problem of drawing abnormal pixels
            //CGImage cgImage = image.CGImage;
            //var info = new SKImageInfo((int)cgImage.Width, (int)cgImage.Height);
            //var bitmap = new SKBitmap(info);
            //using (var pixmap = bitmap.PeekPixels())
            //using (var colorSpace = CGColorSpace.CreateDeviceRGB())
            //using (var context = new CGBitmapContext(pixmap.GetPixels(), pixmap.Width, pixmap.Height, 8, pixmap.RowBytes, colorSpace, CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Big))
            //{
            //    CheckBytes(bitmap.Bytes);
            //    CGRect rect = new CGRect(0, 0, cgImage.Width, cgImage.Height);
            //    context.ClearRect(rect);
            //    CheckBytes(bitmap.Bytes);
            //    context.DrawImage(rect, cgImage);
            //    CheckBytes(bitmap.Bytes);
            //}
            //return bitmap;
#endif
        }
コード例 #11
0
ファイル: DroidPicture.cs プロジェクト: chen2qu/pinyin
        async void IPicture.SavePictureToDisk(ImageSource imgSrc, string fileName)
        {
            var renderer = new FileImageSourceHandler();
            var photo    = await renderer.LoadImageAsync(imgSrc, Android.App.Application.Context);

            if (photo == null)
            {
#if DEBUG
                Console.WriteLine("!!!LoadImage failed!!!");
#endif
                return;
            }

            var dir  = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
            var Dcim = dir.AbsolutePath;

            string cameraFolder = System.IO.Path.Combine(Dcim, "Camera");
            string jpgFileName  = System.IO.Path.Combine(cameraFolder, fileName);
#if DEBUG
            Console.WriteLine("!!!file path to save: " + jpgFileName);
#endif

            try
            {
                var stream = new FileStream(jpgFileName, FileMode.Create);
                photo.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                stream.Close();
#if DEBUG
                Console.WriteLine("!!!!File saved!!!!");
#endif

                //mediascan adds the saved image into the gallery
                // this code will return error: [SendBroadcastPermission] action:android.intent.action.MEDIA_SCANNER_SCAN_FILE, mPermissionType:0
                var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                mediaScanIntent.SetData(Android.Net.Uri.FromFile(new Java.IO.File(jpgFileName)));
                Xamarin.Forms.Forms.Context.SendBroadcast(mediaScanIntent);
            }
            catch (SystemException e)
            {
#if DEBUG
                System.Console.WriteLine(e.Message);
#endif
            }
        }
コード例 #12
0
        async void SetMasterLeftBarButton(UIViewController containerController, MasterDetailPage masterDetailPage)
        {
            if (!masterDetailPage.ShouldShowToolbarButton())
            {
                containerController.NavigationItem.LeftBarButtonItem = null;
                return;
            }

            EventHandler handler = (o, e) => masterDetailPage.IsPresented = !masterDetailPage.IsPresented;

            bool shouldUseIcon = masterDetailPage.Master.Icon != null;

            if (shouldUseIcon)
            {
                try
                {
                    // Simplified the following code because we do not have access to Internals.Registrar.
                    //
                    // var source = Internals.Registrar.Registered.GetHandler<IImageSourceHandler>(masterDetailPage.Master.Icon.GetType());
                    var source = new FileImageSourceHandler();
                    var icon   = await source.LoadImageAsync(masterDetailPage.Master.Icon);

                    containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(icon, UIBarButtonItemStyle.Plain, handler);
                }
                catch (Exception)
                {
                    // Throws Exception otherwise would catch more specific exception type
                    shouldUseIcon = false;
                }
            }

            if (!shouldUseIcon)
            {
                containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(masterDetailPage.Master.Title, UIBarButtonItemStyle.Plain, handler);
            }
        }
コード例 #13
0
ファイル: iOSPicture.cs プロジェクト: chen2qu/pinyin
        public async void SavePictureToDisk(ImageSource imgSrc, string fileName)
        {
            var renderer = new FileImageSourceHandler();
            var photo    = await renderer.LoadImageAsync(imgSrc);

            var     documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            string  jpgFileName        = System.IO.Path.Combine(documentsDirectory, fileName);
            NSData  imgData            = photo.AsJPEG();
            NSError err   = null;
            bool    saved = imgData.Save(jpgFileName, false, out err);

#if DEBUG
            if (saved)
            {
                Console.WriteLine("!!!!iOS: QRCode file saved!!!");
                //return true;
            }
            else
            {
                Console.WriteLine("!!!iOS: NOT saved as " + jpgFileName + " because " + err.LocalizedDescription);
                //return false;
            }
#endif
        }
        Task <UIImage> GetImage(FileImageSource image)
        {
            var handler = new FileImageSourceHandler();

            return(handler.LoadImageAsync(image));
        }
コード例 #15
0
        Task <Bitmap> GetBitmap(FileImageSource image)
        {
            var handler = new FileImageSourceHandler();

            return(handler.LoadImageAsync(image, this.Control.Context));
        }
コード例 #16
0
        public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            if (LeftTabbedPage.TabItemTemplate != null)
            {
                var cell = LeftTabbedPage.TabItemTemplate.CreateContent() as ViewCellEx;
                cell.BindingContext = MenuItems[indexPath.Row];
                cell.Parent         = LeftTabbedPage;

                var rect = new Rectangle(0, 0, cell.View.WidthRequest, cell.View.HeightRequest);

                cell.View.Layout(rect);

                if (Platform.GetRenderer(cell.View) == null)
                {
                    Platform.SetRenderer(cell.View, Platform.CreateRenderer(cell.View));
                }

                var renderer = Platform.GetRenderer(cell.View);

                var nativeView = renderer.NativeView;
                nativeView.AutoresizingMask = UIViewAutoresizing.All;
                nativeView.ContentMode      = UIViewContentMode.ScaleToFill;
                nativeView.Frame            = new CGRect(0, 0, cell.View.WidthRequest, cell.View.HeightRequest);
                nativeView.SetNeedsLayout();


                var nativeCell = new UITableViewCell();
                nativeCell.Frame          = new CGRect(0, 0, cell.View.WidthRequest, cell.View.HeightRequest);
                nativeCell.SelectionStyle = UITableViewCellSelectionStyle.None;
                foreach (var subView in nativeCell.ContentView.Subviews)
                {
                    subView.RemoveFromSuperview();
                }

                nativeCell.AddSubview(nativeView);
                return(nativeCell);
            }
            else
            {
                var cell = tableView.DequeueReusableCell(UIVerticalTabbarViewCell.Key);
                cell.SelectionStyle = UITableViewCellSelectionStyle.None;
                var item = MenuItems[indexPath.Row];
                if (cell is UIVerticalTabbarViewCell verticalTabbarViewCell)
                {
                    verticalTabbarViewCell.TitleView.Text = item.Title;
                    // verticalTabbarViewCell.IconView.Image = new UIImage(item.Icon).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                    var imageSource = item.IconImageSource;
                    if (imageSource is FileImageSource fileImageSource)
                    {
                        var fileImageSOurceHandler = new FileImageSourceHandler();
                        var image = fileImageSOurceHandler.LoadImageAsync(imageSource).Result;
                        if (image != null)
                        {
                            verticalTabbarViewCell.IconView.Image =
                                image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                        }
                    }

                    if (indexPath.Row == 0)
                    {
                        verticalTabbarViewCell.TitleView.TextColor = UIColor.Orange;
                        verticalTabbarViewCell.IconView.TintColor  = UIColor.Orange;
                    }
                    else
                    {
                        verticalTabbarViewCell.TitleView.TextColor = UIColor.Gray;
                        verticalTabbarViewCell.IconView.TintColor  = UIColor.Gray;
                    }
                }

                return(cell);
            }
        }