Exemple #1
0
        public ClipboardService()
        {
            History = new List <ClipboardData>();

            ClipboardNotification.ClipboardUpdate += (s, a) =>
            {
                try
                {
                    _log.Info("UPDATE");
                    History.Insert(0, ClipboardData.Create());
                    _log.Info("/UPDATE");

                    RemoveDupes();

                    while (History.Count > 10)
                    {
                        History.RemoveAt(History.Count - 1);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error($"Error while processing clipboard entry: '{ex.Message}'.", ex);
                }
            };
        }
Exemple #2
0
        private static void LoadImage(ClipboardData cd)
        {
            var imgStream = new MemoryStream();

            var img = Clipboard.GetImage();

            img.Save(imgStream, ImageFormat.Png);
            cd.Image = imgStream;

            using (var thumbStream = new MemoryStream())
            {
                var ratio = (float)img.Height / (float)img.Width;
                var thumb = img.GetThumbnailImage(50, (int)Math.Ceiling(50f * ratio), new System.Drawing.Image.GetThumbnailImageAbort(() => false), IntPtr.Zero);
                thumb.Save(thumbStream, ImageFormat.Png);
                cd.ImageThumbnail = thumbStream.ToArray();
            }
        }
Exemple #3
0
        public static ClipboardData Create()
        {
            var isText  = Clipboard.ContainsText();
            var isImage = Clipboard.ContainsImage();

            var cd = new ClipboardData();

            if (isText)
            {
                cd.IsText = true;
                cd.Text   = Clipboard.GetText();
            }

            if (isImage)
            {
                cd.IsImage = true;

                LoadImage(cd);
            }

            return(cd);
        }
Exemple #4
0
 public void Restore(ClipboardData data)
 {
     _log.Info("RESTORE");
     data.Restore();
     _log.Info("/RESTORE");
 }