Ejemplo n.º 1
0
        private async Task UploadToAzure(Image dbImage, SKCodec codec, CloudBlobContainer container, int desiredWidth)
        {
            var ratio          = (float)desiredWidth / (float)codec.Info.Width;
            var supportedScale = codec.GetScaledDimensions(ratio);

            SKEncodedImageFormat target = codec.EncodedFormat == SKEncodedImageFormat.Gif ? SKEncodedImageFormat.Gif : SKEncodedImageFormat.Png;

            var width  = supportedScale.Width;
            var height = supportedScale.Height;
            var format = target.ToString();
            var name   = $"{dbImage.Slug}_{width}_{height}";

            var blobRef = container.GetBlockBlobReference(name);
            var url     = blobRef.StorageUri.PrimaryUri.ToString();

            using (var resultBitmap = SKBitmap.Decode(codec))
                using (var resizedBitmap = resultBitmap.Resize(new SKImageInfo(supportedScale.Width, supportedScale.Height), SKBitmapResizeMethod.Lanczos3))
                    using (var resultImage = SKImage.FromBitmap(resizedBitmap))
                        using (var imageStream = resultImage.Encode(target, 100).AsStream())
                        {
                            using (var outputSTream = await blobRef.OpenWriteAsync())
                            {
                                await imageStream.CopyToAsync(outputSTream);
                            }
                        }

            var data = new AzureAdapterMetadata(this.account.BlobEndpoint.ToString(), container.Name, name, url);

            await this.imageData.SetImageLinks(new ImageLink(dbImage.Id, null, width, height, format, ImageAdapter.AzureFile, data.ToString()));
        }
Ejemplo n.º 2
0
 void OnFormatPickerChanged(object sender, EventArgs e)
 {
     if (formatPicker.SelectedIndex != -1)
     {
         SKEncodedImageFormat imageFormat = (SKEncodedImageFormat)formatPicker.SelectedItem;
         fileNameEntry.Text = Path.ChangeExtension(fileNameEntry.Text, imageFormat.ToString().ToLower());
     }
 }
        public SaveImagePage()
        {
            InitializeComponent();
            SKEncodedImageFormat imageFormat = SKEncodedImageFormat.Png;

            fileNameEntry.Text = Path.ChangeExtension(fileNameEntry.Text, imageFormat.ToString());
            statusLabel.Text   = "OK";
        }
Ejemplo n.º 4
0
 public static void saveBitmap(SKBitmap bitmap, string path, SKEncodedImageFormat encoding)
 {
     path = Path.ChangeExtension(path, encoding.ToString().ToLower());
     using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) {
         SKData data = SKImage.FromBitmap(bitmap).Encode(SKEncodedImageFormat.Jpeg, 100);
         data.SaveTo(fs);
     }
 }
Ejemplo n.º 5
0
 private UIElement ConvertedRendering(byte[] data, SKEncodedImageFormat format)
 => Rendering(Convert(data, format), format.ToString());