Ejemplo n.º 1
0
 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();
     });
 }
Ejemplo n.º 2
0
 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));
     }));
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public Size Size(PlatformImage image)
 {
     return((Size)((UIImage)image.Native).Size);
 }
Ejemplo n.º 5
0
 public static Drawable Drawable(this PlatformImage image)
 {
     return(image.Native as Drawable);
 }
Ejemplo n.º 6
0
        public Size Size(PlatformImage image)
        {
            var nativeImage = image.Native as Drawable;

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