// take a snapshot on push gesture, and tweet it
        public void tweetSnapShot(TwitterContext ctx)
        {
            // create a png bitmap encoder which knows how to save a .png file
            BitmapEncoder encoder = new PngBitmapEncoder();

            // create frame from the writable bitmap and add to encoder
            encoder.Frames.Add(BitmapFrame.Create(this.colorBitmap));

            string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat);
            string saveDirectory = @"..\..\Snapshots";
            string filename = "KinectSnapshot-" + time + ".png";
            string path = System.IO.Path.Combine(saveDirectory, filename);

            // write the new file to disk
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Create))
                {
                    encoder.Save(fs);
                }
            }
            catch (IOException)
            {
                Console.WriteLine("Saving Snapshot Failed");
            }

            var mediaItems =
            new List<Media>
            {
                new Media
                {
                    Data = Utilities.GetFileBytes(path),
                    FileName = filename,
                    ContentType = MediaContentType.Png
                }
            };
            // tweeting with media takes the picture file and the status message
            var tweet = ctx.TweetWithMedia("Tweeting with media! #KineXionZ",false,mediaItems);
        }
Example #2
0
        static void TweetWithMediaDemo(TwitterContext twitterCtx)
        {
            string status = "Testing TweetWithMedia #Linq2Twitter £ " + DateTime.Now.ToString(CultureInfo.InvariantCulture);
            const bool PossiblySensitive = false;
            const decimal Latitude = StatusExtensions.NoCoordinate; //37.78215m;
            const decimal Longitude = StatusExtensions.NoCoordinate; // -122.40060m;
            const bool DisplayCoordinates = false;

            const string ReplaceThisWithYourImageLocation = @"..\..\images\200xColor_2.png";

            var mediaItems =
                new List<Media>
                {
                    new Media
                    {
                        Data = Utilities.GetFileBytes(ReplaceThisWithYourImageLocation),
                        FileName = "200xColor_2.png",
                        ContentType = MediaContentType.Png
                    }
                };

            Status tweet = twitterCtx.TweetWithMedia(
                status, PossiblySensitive, Latitude, Longitude,
                null, DisplayCoordinates, mediaItems, null);

            Console.WriteLine("Media item sent - Tweet Text: " + tweet.Text);
        }