private void CopyImage_Click(object sender, RoutedEventArgs e) { var data = new DataPackage(); var bi = FirstImage.Source as BitmapImage; var uri = bi.UriSource; data.SetBitmap(RandomAccessStreamReference.CreateFromUri(uri)); Clipboard.SetContent(data); }
/// <summary> /// Sets the current bitmap content that is stored in the clipboard. /// </summary> /// <param name="content">The bitmap content that is stored in the clipboard.</param> public virtual void SetBitmap(Stream content) { var package = new DataPackage(); var random = content.AsRandomAccessStream(); var reference = RandomAccessStreamReference.CreateFromStream(random); package.SetBitmap(reference); }
private static void FillPackage(StorageFile[] files, DataPackage package, object subShareItem) { if (subShareItem != null) { switch (subShareItem.GetType().Name) { case nameof(TextShareItem): { package.SetText((subShareItem as TextShareItem).Text); } break; case nameof(ApplicationLinkShareItem): { var sitm = subShareItem as ApplicationLinkShareItem; package.SetApplicationLink(sitm.ApplicationLink); } break; case nameof(DelayRenderedImageShareItem): { var sitm = subShareItem as DelayRenderedImageShareItem; package.SetBitmap(RandomAccessStreamReference.CreateFromStream(sitm.SelectedImage.GetRandowmAccessStream())); } break; case nameof(FilesShareItem): { StorageFile[] resultArray = files; package.SetStorageItems(resultArray); } break; case nameof(HtmlShareItem): { var sitm = subShareItem as HtmlShareItem; var fmt = HtmlFormatHelper.CreateHtmlFormat(sitm.HtmlFragment); package.SetHtmlFormat(fmt); package.SetText(sitm.HtmlFragment); } break; case nameof(WebLinkShareItem): { var sitm = subShareItem as WebLinkShareItem; package.SetWebLink(sitm.WebLink); package.SetText(sitm.WebLink?.ToString()); } break; default: break; } } }
private bool GetShareContent(DataRequest request) { bool succeeded = false; if (this.flipView.SelectedItem != null) { var item = (Item)this.flipView.SelectedItem; // string customData = @"{ // ""type"" : ""http://schema.org/Product"", // ""properties"" : // { // ""url"" : ""#URL#"", // ""description"" : ""#DESC#"", // ""name"" : ""#NAME#"", // ""model"" : ""#MODEL#"", // ""price"" : ""#PRICE#"" // } // }"; // customData = customData.Replace("#URL#", item.Uri).Replace("#DESC#", item.Descricao).Replace("#NAME#", item.Nome).Replace("#MODEL#", item.Categoria.Nome).Replace("#PRICE#", "R$ " + item.Valor); requestData = request.Data; //requestData.SetData("http://schema.org/Product", customData); requestData.Properties.Title = item.Nome == null ? "Imagem compartilhada" : item.Nome; requestData.Properties.Description = item.Descricao; RandomAccessStreamReference imageStreamRef = null; imageStreamRef = RandomAccessStreamReference.CreateFromUri(new Uri(_baseUri, item.ImageUrl)); if (imageStreamRef != null) { requestData.SetUri(new Uri(_baseUri, item.ImageUrl)); requestData.Properties.Title = string.Format("{0} - {1}", Win8CatalogApplication.Instance.Empresa.Nome, item.Nome); requestData.Properties.Description = item.Descricao; requestData.SetText(item.Descricao); requestData.Properties.Thumbnail = imageStreamRef; requestData.SetBitmap(imageStreamRef); succeeded = true; } } else { request.FailWithDisplayText("Selecione a imagem que deseja compartilhar e tente novamente."); } return succeeded; }
async private void CopyBitmap(bool isDelayRendered) { var imagePicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary, FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" } }; var imageFile = await imagePicker.PickSingleFileAsync(); if (imageFile != null) { var dataPackage = new DataPackage(); // Use one click handler for two operations: regular copy and copy using delayed rendering // Differentiate the case by the button name if (isDelayRendered) { dataPackage.SetDataProvider(StandardDataFormats.Bitmap, request => OnDeferredImageRequestedHandler(request, imageFile)); OutputText.Text = "Image has been copied using delayed rendering"; } else { dataPackage.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile)); OutputText.Text = "Image has been copied"; } try { Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage); } catch (Exception ex) { // Copying data to Clipboard can potentially fail - for example, if another application is holding Clipboard open rootPage.NotifyUser("Error copying content to Clipboard: " + ex.Message + ". Try again", NotifyType.ErrorMessage); } } else { OutputText.Text = "No image was selected."; } }
/// <summary> /// Скопировать в клипоборд. /// </summary> public async Task CopyToClipboard() { var dp = new DataPackage(); var storage = ServiceLocator.Current.GetServiceOrThrow<IStorageService>(); var f = await storage.FullSizeMediaFiles.GetFromMediaStorage(link); dp.SetBitmap(RandomAccessStreamReference.CreateFromFile(f)); Clipboard.SetContent(dp); Clipboard.Flush(); }
private async void CopyCommands(object sender, TappedRoutedEventArgs e) { var dataPackage = new DataPackage(); dataPackage.RequestedOperation = DataPackageOperation.Copy; var image = SelectedPod.CurrentImage; var uri = await Q42.WinRT.Data.WebDataCache.GetLocalUriAsync(new Uri(image.URL)); var m = sender as MenuItem; switch (m.Text) { case COPY_IMAGE: dataPackage.SetBitmap(RandomAccessStreamReference.CreateFromUri(uri)); break; case COPY_PLAIN: dataPackage.SetText(image.Alt); break; case COPY_URL: dataPackage.SetText(image.URL); break; } Clipboard.SetContent(dataPackage); }