Esempio n. 1
0
        /// <summary>
        /// Changes the dimensions of all image in <see cref="WorkingPath"/> with <see cref="oldX"/> x <see cref="oldY"/> to <see cref="newX"/> x <see cref="newY"/>.
        /// </summary>
        /// <param name="oldX">Old width</param>
        /// <param name="oldY">Old height</param>
        /// <param name="newX">New width</param>
        /// <param name="newY">New height</param>
        public void Resize(int oldX, int oldY, int newX, int newY)
        {
            foreach (var file in Directory.EnumerateFiles(WorkingPath, "*.png", SearchOption.AllDirectories))
            {
                string tmpFile = file + ".tmp";
                using (var image = Image.FromFile(file))
                {
                    if (image.Width != oldX || image.Height != oldY)
                    {
                        continue;
                    }

                    using (var bitmap = ResizeImage(image, newX, newY))
                    {
                        bitmap.Save(tmpFile, ImageFormat.Png);
                        ImageResized?.Invoke(this, new ImageResizedEventArgs(file, oldX, oldY, newX, newY));
                    }
                }

                File.Delete(file);
                File.Move(tmpFile, file);
            }
        }
Esempio n. 2
0
 public void GetResizedImageUrl(string downloadUrl, Action <IResizeResponse> onTokenFetched)
 {
     Task.Run(async() =>
     {
         try
         {
             var client     = new HttpClient();
             var requestObj = new DefaultResizeRequest()
             {
                 Url = downloadUrl
             };
             var response = await client.PostAsync(backendUrl, new StringContent(JsonConvert.SerializeObject(requestObj)));
             if (response.IsSuccessStatusCode)
             {
                 var stringData = await response.Content.ReadAsStringAsync();
                 if (JsonConvert.DeserializeObject(stringData, responeType) is IResizeResponse data)
                 {
                     if (string.IsNullOrEmpty(data.Token))
                     {
                         onTokenFetched(data);
                         ImageResized?.Invoke(this, data);
                     }
                 }
             }
             else
             {
                 // TODO Maybe add som feature for reporting this
             }
         }
         catch (Exception ex)
         {
             // TODO Maybe add som feature for reporting this
             //throw ex;
         }
     });
 }
Esempio n. 3
0
        public static void UpdateImageResizers(Image image)
        {
            AdornerLayer noteEditorAdornerLayer = AdornerLayer.GetAdornerLayer(_noteEditor);

            if (_currentResizingAdorner != null)
            {
                ClearImageResizers();
            }

            _currentResizingAdorner = new ResizingAdorner(image, _noteEditor.ActualWidth, _noteEditor.ActualHeight);
            _currentResizingAdorner.AdornerResized += () =>
            {
                if (_imageResized == false)
                {
                    _imageResized = true;
                    ImageResized?.Invoke();

                    System.Diagnostics.Debug.WriteLine($"{DateTime.Now.TimeOfDay} - [Event] AdornerResized triggered");
                }
            };

            noteEditorAdornerLayer.Add(_currentResizingAdorner);
            noteEditorAdornerLayer.Update();
        }