public async Task Write(PlatformImage image, System.IO.Stream stream, CancellationToken token)
 {
     await Task.Run(async() =>
     {
         var impl = image.Native as BitmapDrawable;
         if (impl == null)
         {
             throw new ImageOperationException();
         }
         var bitmap = impl.Bitmap;
         await bitmap.CompressAsync(Bitmap.CompressFormat.Png, 100, stream);
         token.ThrowIfCancellationRequested();
     });
 }
 public Task <PlatformImage> Resize(PlatformImage image, float sx, float sy)
 {
     return(Task.Run(() =>
     {
         var impl = image.Native as BitmapDrawable;
         if (impl == null)
         {
             throw new ImageOperationException();
         }
         var b = impl.Bitmap;
         var sizeX = Math.Round(impl.IntrinsicWidth * sx);
         var sizeY = Math.Round(impl.IntrinsicHeight * sy);
         var resized = Bitmap.CreateScaledBitmap(b, (int)sizeX, (int)sizeY, false);
         return new PlatformImage(new BitmapDrawable(resized));
     }));
 }
Beispiel #3
0
        private async Task <bool> MakeLoadTask(CancellationToken token)
        {
            try
            {
                Stream stream     = null;
                var    httpClient = MakeHttpClient();
                using (var response = await httpClient.GetAsync(Uri, token))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        stream = await response.Content.ReadAsStreamAsync();
                    }
                    else
                    {
                        throw new HttpRequestException(response.ReasonPhrase);
                    }
                }

                using (var buffer = new MemoryStream())
                {
                    await stream.CopyToAsync(buffer, 4096, token);

                    buffer.Position = 0;
                    Bitmap          = await PlatformImage.LoadFromStream(buffer, token);
                }

                IsLoaded = true;
                return(true);
            }
            catch (HttpRequestException e)
            {
                LoadError = e;
            }
            catch (IOException e)
            {
                LoadError = e;
            }
            return(false);
        }
 public Size Size(PlatformImage image)
 {
     return((Size)((UIImage)image.Native).Size);
 }
 public static Drawable Drawable(this PlatformImage image)
 {
     return(image.Native as Drawable);
 }
        public Size Size(PlatformImage image)
        {
            var nativeImage = image.Native as Drawable;

            return(new Size(nativeImage.IntrinsicWidth, nativeImage.IntrinsicHeight));
        }
Beispiel #7
0
 public RemoteImage(Uri uri, PlatformImage img) : this(uri)
 {
     IsLoaded = true;
     Bitmap   = img;
 }
Beispiel #8
0
 void IPlatformRemoteImageView.SetImage(PlatformImage image)
 {
     SetImageDrawable(image.Drawable());
 }
Beispiel #9
0
 void IPlatformRemoteImageView.SetImage(PlatformImage image)
 {
     ImageView.Image = image.UIImage();
 }