예제 #1
0
 private void ShowNextImage(bool forward)
 {
     GiphyDotNet.Model.GiphyImage.Data data = null;
     lock (m_resultLock)
     {
         if (m_currentResults == null)
         {
             return;
         }
         if (forward)
         {
             if (m_currentResultShown + 1 >= m_currentResults.Data.Length)
             {
                 return;
             }
             m_currentResultShown++;
         }
         else
         {
             if (m_currentResultShown - 1 < 0)
             {
                 return;
             }
             m_currentResultShown--;
         }
         data = m_currentResults.Data[m_currentResultShown];
     }
     if (data != null)
     {
         ShowResult(data);
     }
 }
예제 #2
0
        private void ShowResult(GiphyDotNet.Model.GiphyImage.Data data)
        {
            // Get the gif into the media element.
            ui_result.Source = new Uri(data.Images.Original.Mp4);

            // Fade it in.
            FadeIn(ui_result);
        }
예제 #3
0
        public static bool SetClipboardContent(GiphyDotNet.Model.GiphyImage.Data data)
        {
            try
            {
                string actaulGifUrl = data.Images.Original.Url;
                int    gifPos       = actaulGifUrl.ToLower().IndexOf(s_gifSuffix);
                if (gifPos != -1)
                {
                    gifPos      += s_gifSuffix.Length;
                    actaulGifUrl = actaulGifUrl.Substring(0, gifPos);
                }

                // Get a temp path to the file
                string tempFolder = Path.GetTempPath();
                string tempPath   = tempFolder + s_copyTempFileName;

                // Download it
                using (var client = new WebClient())
                {
                    client.DownloadFile(actaulGifUrl, tempPath);
                }

                // Open it as a bitmap
                BitmapSource img = new BitmapImage(new Uri(tempPath));

                // Setup the drop file locations
                List <string> dropFiles = new List <string>();
                dropFiles.Add(tempPath);
                StringCollection dropFileCollection = new StringCollection();
                dropFileCollection.AddRange(dropFiles.ToArray());

                // Setup the move effect buffer (this is part of the drop files
                byte[]       moveEffect = new byte[] { 2, 0, 0, 0 };
                MemoryStream dropEffect = new MemoryStream();
                dropEffect.Write(moveEffect, 0, moveEffect.Length);

                // Setup the HTML format - this is what most apps use
                string htmlFormat = CreateClipboardHtmlFormat(actaulGifUrl);

                DataObject clipData = new DataObject();

                // These files allow the program to access the local gif.
                clipData.SetFileDropList(dropFileCollection);
                clipData.SetData("Preferred DropEffect", dropEffect);

                // This is the heavy lifter, most apps use this to actually get the gif.
                clipData.SetData("HTML Format", htmlFormat);
                clipData.SetText(actaulGifUrl);

                // Most apps don't use the image, but it must be here for them to want to use the gif html right.
                clipData.SetImage(img);

                // Clear the current clipboard and set our data.
                Clipboard.Clear();
                Clipboard.SetDataObject(clipData, true);
            }
            catch
            {
                return(false);
            }
            return(true);
        }