Inheritance: IDataPackageView
        private async void textBox_GotFocus(object sender, RoutedEventArgs e)
        {
            Windows.ApplicationModel.DataTransfer.DataPackageView contents = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            IReadOnlyList <string> types = contents.AvailableFormats;

            foreach (var t in types)
            {
                System.Diagnostics.Debug.WriteLine(t);
            }
            string s = "";

            try
            {
                if (contents.Contains("Text"))
                {
                    s = await contents.GetTextAsync();
                }
            }
            catch (Exception) // I'll have to check the format types before doing a get.
            {
                throw;
            }
            this.textBox.Text = s;
            Uri blah;

            if (Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out blah))
            {
                this.textBox.SelectAll();
            }
        }
示例#2
0
文件: model.cs 项目: lindexi/Markdown
        public async Task<string> clipboard(DataPackageView con)
        {
            string str = string.Empty;
            //文本
            if (con.Contains(StandardDataFormats.Text))
            {
                str = await con.GetTextAsync();
                return str;
            }

            //图片
            if (con.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference img = await con.GetBitmapAsync();
                var imgstream = await img.OpenReadAsync();
                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(imgstream);

                WriteableBitmap src = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                src.SetSource(imgstream);

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(imgstream);
                PixelDataProvider pxprd =
                    await
                        decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight,
                            new BitmapTransform(), ExifOrientationMode.RespectExifOrientation,
                            ColorManagementMode.DoNotColorManage);
                byte[] buffer = pxprd.DetachPixelData();

                str = "image";
                StorageFolder folder = await _folder.GetFolderAsync(str);

                StorageFile file =
                    await
                        folder.CreateFileAsync(
                            DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +
                            DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                            (ran.Next()%10000).ToString() + ".png", CreationCollisionOption.GenerateUniqueName);

                using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, decoder.PixelWidth,
                        decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer);
                    await encoder.FlushAsync();

                    str = $"![这里写图片描述](image/{file.Name})\n";
                }
            }

            //文件
            if (con.Contains(StandardDataFormats.StorageItems))
            {
                var filelist = await con.GetStorageItemsAsync();
                StorageFile file = filelist.OfType<StorageFile>().First();
                return await imgfolder(file);
            }

            return str;
        }
示例#3
0
        public static DataPackageView GetContent()
        {
            var dataPackageView = new DataPackageView();
            var pasteboard      = NSPasteboard.GeneralPasteboard;
            var clipboardText   = pasteboard.GetStringForType(NSPasteboard.NSPasteboardTypeString);

            dataPackageView.SetText(clipboardText);
            return(dataPackageView);
        }
示例#4
0
        public static DataPackageView GetContent()
        {
            var dataPackageView = new DataPackageView();

            if (UIPasteboard.General.String != null)
            {
                dataPackageView.SetFormatTask(StandardDataFormats.Text, Task.FromResult(UIPasteboard.General.String));
            }
            return(dataPackageView);
        }
示例#5
0
        public static string GetHtmlText(this Windows.ApplicationModel.DataTransfer.DataPackageView dpv)
        {
            var task = Task.Run(async() =>
            {
                var result = await dpv.GetHtmlFormatAsync();
                return(result);
            });

            return(task.Result);
        }
示例#6
0
        public static DataPackageView GetContent()
        {
            var manager = ContextHelper.Current.GetSystemService(Context.ClipboardService) as ClipboardManager;

            if (manager is null)
            {
                return(null);
            }

            var clipData = manager.PrimaryClip;

            string clipText = null;
            Uri    clipUri  = null;
            string clipHtml = null;

            for (int itemIndex = 0; itemIndex < clipData.ItemCount; itemIndex++)
            {
                var itemText = clipData.GetItemAt(itemIndex).Text;
                if (itemText != null)
                {
                    clipText = itemText;
                }
                var itemUri = clipData.GetItemAt(itemIndex).Uri;
                if (itemUri != null)
                {
                    clipUri = new Uri(itemUri.ToString());
                }
                var itemHtml = clipData.GetItemAt(itemIndex).HtmlText;
                if (itemText != null)
                {
                    clipHtml = itemHtml;
                }
            }

            var clipView = new DataPackageView();

            if (clipText != null)
            {
                clipView.SetFormatTask(StandardDataFormats.Text, Task.FromResult(clipText));
            }

            if (clipHtml != null)
            {
                clipView.SetFormatTask(StandardDataFormats.Html, Task.FromResult(clipHtml));
            }

            if (clipUri != null)
            {
                clipView.SetFormatTask(StandardDataFormats.Uri, Task.FromResult(clipUri));
                clipView.SetFormatTask(StandardDataFormats.WebLink, Task.FromResult(clipUri));
            }

            return(clipView);
        }
示例#7
0
        private static async Task <string> GetTextAsync()
        {
            DT.DataPackageView dataContent = DT.Clipboard.GetContent();

            if (dataContent.AvailableFormats.Contains("Text"))
            {
                return(await dataContent.GetTextAsync("Text"));
            }

            return(string.Empty);
        }
示例#8
0
        public static DataPackageView GetContent()
        {
            var dataPackageView = new DataPackageView();

            var command     = $"{JsType}.getText()";
            var getTextTask = WebAssemblyRuntime.InvokeAsync(command);

            dataPackageView.SetFormatTask(StandardDataFormats.Text, getTextTask);

            return(dataPackageView);
        }
示例#9
0
        public static DataPackageView GetContent()
        {
            var dataPackageView = new DataPackageView();
            var pasteboard      = NSPasteboard.GeneralPasteboard;
            var clipboardText   = pasteboard.GetStringForType(NSPasteboard.NSPasteboardTypeString);

            if (clipboardText != null)
            {
                dataPackageView.SetFormatTask(StandardDataFormats.Text, Task.FromResult(clipboardText));
            }
            return(dataPackageView);
        }
示例#10
0
        internal static async Task <Uri?> GetSharedUriAsync(DataPackageView view)
        {
            if (view.Contains(StandardDataFormats.Uri))
            {
                return(await view.GetUriAsync());
            }
            else if (view.Contains(StandardDataFormats.WebLink))
            {
                return(await view.GetWebLinkAsync());
            }
            else if (view.Contains(StandardDataFormats.ApplicationLink))
            {
                return(await view.GetApplicationLinkAsync());
            }

            return(null);
        }
        private async static Task<IThing> GetStructuredDataInternal(DataPackageView dataPackage, string formatId)
        {
            IThing thing = null;

            try
            {
                var data = await dataPackage.GetDataAsync(formatId);
                if (data != null)
                    thing = Parse(data.ToString());
            }
            catch
            {
                return null;
            }


            return thing;
        }
        private async Task<String> FormatOfSharedData(DataPackageView shardedData)
        {
            String newString = "";


            if (shardedData.Contains(StandardDataFormats.Rtf))
            { newString = this._shareOperation.Data.GetRtfAsync().ToString(); }
            else

                if (shardedData.Contains(StandardDataFormats.Text))
                { newString = await this._shareOperation.Data.GetTextAsync(); }
                else

                    if (shardedData.Contains(StandardDataFormats.Html))
                    { newString = this._shareOperation.Data.GetHtmlFormatAsync().ToString(); }
                    else
                        newString = "Could not share content.";

            return newString;
        }
示例#13
0
        protected async Task SetDataAsync(uwpDataTransfer.DataPackageView content)
        {
            this.AvailableFormats       = content.AvailableFormats?.ToList() ?? (new List <string>());
            this.IsFromRoamingClipboard = content.Properties.IsFromRoamingClipboard;

            // テキストデータ
            this.TextHead = string.Empty;
            if (content.Contains(uwpDataTransfer.StandardDataFormats.WebLink)) //"UniformResourceLocatorW"
            {
                this.TextHead = (await content.GetWebLinkAsync()).ToString();
            }
            if (content.Contains(uwpDataTransfer.StandardDataFormats.Text)) //"Text"
            {
                this.TextHead = await content.GetTextAsync();
            }

            if (this.TextHead.Length > TextHeadLength)
            {
                this.TextHead = $"{this.TextHead.Substring(0, TextHeadLength)}(以下略)";
            }

            // ビットマップデータ
            this.Bitmap = new BitmapImage();
            if (content.Contains(uwpDataTransfer.StandardDataFormats.Bitmap)) //"Bitmap"
            {
                // ビットマップデータの取り出し (ここは UWP と同じにはできない)
                RandomAccessStreamReference stRef = await content.GetBitmapAsync();

                using (IRandomAccessStreamWithContentType uwpStream = await stRef.OpenReadAsync())
                    using (Stream stream = uwpStream.AsStreamForRead())
                    {
                        Bitmap.BeginInit();
                        Bitmap.StreamSource = stream;
                        Bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                        Bitmap.EndInit();
                        Bitmap.Freeze();
                    }
            }
        }
示例#14
0
        public DataPackageView GetView()
        {
            var clipView = new DataPackageView();

            if (Text != null)
            {
                clipView.SetFormatTask(StandardDataFormats.Text, Task.FromResult(Text));
            }

            if (Html != null)
            {
                clipView.SetFormatTask(StandardDataFormats.Html, Task.FromResult(Html));
            }

            if (Uri != null)
            {
                clipView.SetFormatTask(StandardDataFormats.Uri, Task.FromResult(Uri));
                clipView.SetFormatTask(StandardDataFormats.WebLink, Task.FromResult(Uri));
            }

            return(clipView);
        }
示例#15
0
        internal static async Task <NSDraggingItem[]> CreateNativeDragDropData(
            DataPackageView data,
            Point startPoint)
        {
            NSDraggingItem draggingItem;
            var            items             = new List <NSDraggingItem>();
            double         maxFrameDimension = 300.0;     // May be adjusted
            var            defaultFrameRect  = new CoreGraphics.CGRect(startPoint.X, startPoint.Y, 100, 30);

            /* Note that NSDraggingItems are required by the BeginDraggingSession methods.
             * Therefore, that is what is constructed here instead of pasteboard items.
             *
             * For several types such as NSString or NSImage, they implement the INSPasteboardWriting interface and
             * can therefore be used to directly construct an NSDraggingItem.
             * However, for other types (such as HTML) the full pasteboard item must be constructed first defining
             * both its type and string content.
             *
             * The dragging frame is used to represent the visual of the item being dragged. This could be a
             * preview of the image or sample text. At minimum, macOS requires the DraggingFrame property of the
             * NSDraggingItem to be set with a CGRect or the app will crash. It is however better to set both
             * the frame bounds and content at the same time with .SetDraggingFrame(). For caveats see:
             * https://developer.apple.com/documentation/appkit/nsdraggingitem/1528746-setdraggingframe
             *
             * Because Uno does not currently support the DragUI, this code only generates a real drag visual
             * for images where a visual is already defined. For other types such as text, no visual will be
             * generated. In the future, when DragUI and its corresponding image is supported, this can change.
             *
             */

            if (data?.Contains(StandardDataFormats.Bitmap) ?? false)
            {
                NSImage?image = null;

                using (var stream = (await(await data.GetBitmapAsync()).OpenReadAsync()).AsStream())
                {
                    if (stream != null)
                    {
                        using (var ms = new MemoryStream())
                        {
                            await stream.CopyToAsync(ms);

                            ms.Flush();
                            ms.Position = 0;

                            image = NSImage.FromStream(ms);
                        }
                    }
                }

                if (image != null)
                {
                    draggingItem = new NSDraggingItem(image);

                    // For an NSImage, we will use the image itself as the dragging visual.
                    // The visual should be no larger than the max dimension setting and is therefore scaled.
                    NSBitmapImageRep rep = new NSBitmapImageRep(image.CGImage);
                    int    width         = (int)rep.PixelsWide;
                    int    height        = (int)rep.PixelsHigh;
                    double scale         = maxFrameDimension / Math.Max(width, height);

                    // Dragging frame must be set
                    draggingItem.SetDraggingFrame(
                        new CoreGraphics.CGRect(startPoint.X, startPoint.Y, width * scale, height * scale),
                        image);
                    items.Add(draggingItem);
                }
            }

            if (data?.Contains(StandardDataFormats.Html) ?? false)
            {
                var html = await data.GetHtmlFormatAsync();

                if (!string.IsNullOrEmpty(html))
                {
                    var pasteboardItem = new NSPasteboardItem();
                    pasteboardItem.SetStringForType(html, NSPasteboard.NSPasteboardTypeHTML);

                    draggingItem = new NSDraggingItem(pasteboardItem);
                    draggingItem.DraggingFrame = defaultFrameRect;                     // Must be set
                    items.Add(draggingItem);
                }
            }

            if (data?.Contains(StandardDataFormats.Rtf) ?? false)
            {
                var rtf = await data.GetRtfAsync();

                if (!string.IsNullOrEmpty(rtf))
                {
                    // Use `NSPasteboardTypeRTF` instead of `NSPasteboardTypeRTFD` for max compatibility
                    var pasteboardItem = new NSPasteboardItem();
                    pasteboardItem.SetStringForType(rtf, NSPasteboard.NSPasteboardTypeRTF);

                    draggingItem = new NSDraggingItem(pasteboardItem);
                    draggingItem.DraggingFrame = defaultFrameRect;                     // Must be set
                    items.Add(draggingItem);
                }
            }

            if (data?.Contains(StandardDataFormats.StorageItems) ?? false)
            {
                var storageItems = await data.GetStorageItemsAsync();

                if (storageItems.Count > 0)
                {
                    // Not currently supported
                }
            }

            if (data?.Contains(StandardDataFormats.Text) ?? false)
            {
                var text = await data.GetTextAsync();

                if (!string.IsNullOrEmpty(text))
                {
                    draggingItem = new NSDraggingItem((NSString)text);
                    draggingItem.DraggingFrame = defaultFrameRect;                     // Must be set
                    items.Add(draggingItem);
                }
            }

            if (data != null)
            {
                var uri = DataPackage.CombineUri(
                    data.Contains(StandardDataFormats.WebLink) ? (await data.GetWebLinkAsync()).ToString() : null,
                    data.Contains(StandardDataFormats.ApplicationLink) ? (await data.GetApplicationLinkAsync()).ToString() : null,
                    data.Contains(StandardDataFormats.Uri) ? (await data.GetUriAsync()).ToString() : null);

                if (string.IsNullOrEmpty(uri) == false)
                {
                    draggingItem = new NSDraggingItem(new NSUrl(uri));
                    draggingItem.DraggingFrame = defaultFrameRect;                     // Must be set
                    items.Add(draggingItem);
                }
            }

            return(items.ToArray());
        }
		private static async Task<ReceivedShareItem> FetchDataFromPackageViewAsync(DataPackageView packageView)
		{
			var rval = new ReceivedShareItem()
			{
				Title = packageView.Properties.Title,
				Description = packageView.Properties.Description,
				PackageFamilyName = packageView.Properties.PackageFamilyName,
				ContentSourceWebLink = packageView.Properties.ContentSourceWebLink,
				ContentSourceApplicationLink = packageView.Properties.ContentSourceApplicationLink,
				LogoBackgroundColor = packageView.Properties.LogoBackgroundColor,

			};
			if (packageView.Properties.Square30x30Logo != null)
			{
				using (var logoStream = await packageView.Properties.Square30x30Logo.OpenReadAsync())
				{
					var logo = new MemoryStream();
					await logoStream.AsStreamForRead().CopyToAsync(logo);
					logo.Position = 0;
					var str = Convert.ToBase64String(logo.ToArray());
					//rval.Square30x30LogoBase64 = Convert.ToBase64String(logo.ToArray());
					rval.Square30x30Logo = new Models.MemoryStreamBase64Item { Base64String = str };


				}
			}
			if (packageView.Properties.Thumbnail != null)
			{
				using (var thumbnailStream = await packageView.Properties.Thumbnail.OpenReadAsync())
				{
					var thumbnail = new MemoryStream();
					await thumbnailStream.AsStreamForRead().CopyToAsync(thumbnail);
					thumbnail.Position = 0;
					var str = Convert.ToBase64String(thumbnail.ToArray());
					rval.Thumbnail = new Models.MemoryStreamBase64Item { Base64String = str };
				}
			}

			if (packageView.Contains(StandardDataFormats.WebLink))
			{
				try
				{
					var link = new WebLinkShareItem
					{
						WebLink = await packageView.GetWebLinkAsync()
					};

					rval.AvialableShareItems.Add(link);
				}
				catch (Exception ex)
				{
					//NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage);
				}
			}
			if (packageView.Contains(StandardDataFormats.ApplicationLink))
			{
				try
				{
					var sharedApplicationLink = new ApplicationLinkShareItem
					{
						ApplicationLink = await packageView.GetApplicationLinkAsync()
					};
					rval.AvialableShareItems.Add(sharedApplicationLink);

				}
				catch (Exception ex)
				{
					//NotifyUserBackgroundThread("Failed GetApplicationLinkAsync - " + ex.Message, NotifyType.ErrorMessage);
				}
			}
			if (packageView.Contains(StandardDataFormats.Text))
			{
				try
				{
					var sharedText = new TextShareItem { Text = await packageView.GetTextAsync() };
					rval.AvialableShareItems.Add(sharedText);
					rval.Text = await packageView.GetTextAsync();
					//rval.GetValueContainer(x => x.Text)
					//   	.GetNullObservable()
					//	.Subscribe(e => sharedText.Text = rval.Text)
					//	.DisposeWith(rval);
					sharedText.GetValueContainer(x => x.Text)
						.GetNullObservable()
						.Subscribe(e => rval.Text = sharedText.Text)
						.DisposeWith(rval);
				}
				catch (Exception ex)
				{
					//NotifyUserBackgroundThread("Failed GetTextAsync - " + ex.Message, NotifyType.ErrorMessage);
				}
			}
			if (packageView.Contains(StandardDataFormats.StorageItems))
			{
				try
				{
					var files = await packageView.GetStorageItemsAsync();
					var sharedStorageItem = new FilesShareItem
					{
						StorageFiles = new ObservableCollection<FileItem>()
						//StorageItems = 
					};
					foreach (StorageFile sf in files)
					{
						var guidString = Guid.NewGuid().ToString();
						StorageApplicationPermissions.FutureAccessList.AddOrReplace(guidString, sf, sf.Name);
						var ts = await sf.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView);
						var tmbs = new MemoryStream();
						await ts.AsStreamForRead().CopyToAsync(tmbs);
						var file = new FileItem
						{
							AccessToken = guidString,
							ContentType = sf.ContentType,
							FileName = sf.DisplayName,
							PossiblePath = sf.Path,
							Thumbnail = new Models.MemoryStreamBase64Item(tmbs.ToArray())
						};

						sharedStorageItem.StorageFiles.Add(file);

					}
					//StorageApplicationPermissions.FutureAccessList.AddOrReplace()

					rval.AvialableShareItems.Add(sharedStorageItem);
				}
				catch (Exception ex)
				{
					//NotifyUserBackgroundThread("Failed GetStorageItemsAsync - " + ex.Message, NotifyType.ErrorMessage);
				}
			}
			//if (packageView.Contains(dataFormatName))
			//{
			//	try
			//	{
			//		this.sharedCustomData = await packageView.GetTextAsync(dataFormatName);
			//	}
			//	catch (Exception ex)
			//	{
			//		//NotifyUserBackgroundThread("Failed GetTextAsync(" + dataFormatName + ") - " + ex.Message, NotifyType.ErrorMessage);
			//	}
			//}
			if (packageView.Contains(StandardDataFormats.Html))
			{
				var sharedHtmlFormatItem = new HtmlShareItem();
				var sharedHtmlFormat = string.Empty;
				try
				{
					sharedHtmlFormat = await packageView.GetHtmlFormatAsync();
					//sharedHtmlFormatItem.HtmlFormat = sharedHtmlFormat;
					sharedHtmlFormatItem.HtmlFragment = HtmlFormatHelper.GetStaticFragment(sharedHtmlFormat);
				}
				catch (Exception ex)
				{
					//NotifyUserBackgroundThread("Failed GetHtmlFormatAsync - " + ex.Message, NotifyType.ErrorMessage);
				}
				//try
				//{
				//	var sharedResourceMap = await packageView.GetResourceMapAsync();
				//}
				//catch (Exception ex)
				//{
				//	//NotifyUserBackgroundThread("Failed GetResourceMapAsync - " + ex.Message, NotifyType.ErrorMessage);
				//}

				//if (packageView.Contains(StandardDataFormats.WebLink))
				//{
				//	try
				//	{
				//		sharedHtmlFormatItem.WebLink = await packageView.GetWebLinkAsync();
				//	}
				//	catch (Exception ex)
				//	{
				//		//NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage);
				//	}
				//}
				rval.AvialableShareItems.Add(sharedHtmlFormatItem);

			}
			if (packageView.Contains(StandardDataFormats.Bitmap))
			{
				try
				{
					var fi = await packageView.GetBitmapAsync();
					using (var imgFileStream = await fi.OpenReadAsync())
					{
						var saveTargetStream = new InMemoryRandomAccessStream();

						var bitmapSourceStream = imgFileStream;

						await ServiceLocator
								 .Instance
								 .Resolve<IImageConvertService>()
								 .ConverterBitmapToTargetStreamAsync(bitmapSourceStream, saveTargetStream);

						saveTargetStream.Seek(0);
						var sr = saveTargetStream.GetInputStreamAt(0);
						var source = sr.AsStreamForRead();

						var ms = new MemoryStream();
						await source.CopyToAsync(ms);

						var sharedBitmapStreamRef = new DelayRenderedImageShareItem
						{
							SelectedImage = new Models.MemoryStreamBase64Item(ms.ToArray())
						};

						rval.AvialableShareItems.Add(sharedBitmapStreamRef);

					}
				}
				catch (Exception ex)
				{
					//NotifyUserBackgroundThread("Failed GetBitmapAsync - " + ex.Message, NotifyType.ErrorMessage);
				}
			}

			//foreach (var item in rval.AvialableShareItems)
			//{
			//	//item.ContentSourceApplicationLink = rval.ContentSourceApplicationLink;
			//	//item.ContentSourceWebLink = rval.ContentSourceWebLink;
			//	//item.DefaultFailedDisplayText = rval.DefaultFailedDisplayText;
			//	//item.Description = rval.Description;
			//	//item.Title = rval.Title;
			//}
			return rval;
		}
示例#17
0
 public DataPackageView(DataTransfer.DataPackageView View)
 {
     AvailableFormats = View.AvailableFormats;
     this.View        = View;
     Properties       = new DataPackagePropertySetView(View.Properties);
 }
        // Note: this sample is not trying to resolve and render the HTML using resource map.
        // Please refer to the Clipboard JavaScript sample for an example of how to use resource map
        // for local images display within an HTML format. This sample will only demonstrate how to
        // get a resource map object and extract its key values
        async void DisplayResourceMapAsync(DataPackageView dataPackageView)
        {
            OutputResourceMapKeys.Text = Environment.NewLine + "Resource map: ";
            IReadOnlyDictionary<string, RandomAccessStreamReference> resMap = null;
            try
            {
                resMap = await dataPackageView.GetResourceMapAsync();
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Error retrieving Resource map from Clipboard: " + ex.Message, NotifyType.ErrorMessage);
            }

            if (resMap != null)
            {
                if (resMap.Count > 0)
                {
                    foreach (var item in resMap)
                    {
                        OutputResourceMapKeys.Text += Environment.NewLine + "Key: " + item.Key;
                    }
                }
                else
                {
                    OutputResourceMapKeys.Text += Environment.NewLine + "Resource map is empty";
                }
            }
        }
示例#19
0
 public Detector(DataPackageView data)
 {
     myData = data;
     Detected = new DetectedItems();
 }
示例#20
0
        private async Task<string> clipboard(DataPackageView con)
        {
            string str = string.Empty;
            //文本
            if (con.Contains(StandardDataFormats.Text))
            {
                str = await con.GetTextAsync();
                return str;
            }

            //图片
            if (con.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference img = await con.GetBitmapAsync();
                IRandomAccessStreamWithContentType imgstream = await img.OpenReadAsync();
                BitmapDecoder decoder =
                    await BitmapDecoder.CreateAsync(imgstream);
                PixelDataProvider pxprd =
                    await
                        decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8,
                            BitmapAlphaMode.Straight,
                            new BitmapTransform(),
                            ExifOrientationMode.RespectExifOrientation,
                            ColorManagementMode.DoNotColorManage);
                byte[] buffer = pxprd.DetachPixelData();

                StorageFile temp = await image_storage(file);

                using (IRandomAccessStream file_stream = await temp.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder encoder =
                        await
                            BitmapEncoder.CreateAsync(
                                BitmapEncoder.PngEncoderId, file_stream);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Straight, decoder.PixelWidth, decoder.PixelHeight,
                        decoder.DpiX, decoder.DpiY, buffer);
                    await encoder.FlushAsync();

                    str = $"![这里写图片描述]({file.folder}/{temp.Name})\n";
                    return str;
                }
            }

            //文件
            if (con.Contains(StandardDataFormats.StorageItems))
            {
                str = (await con.GetStorageItemsAsync()).OfType<StorageFile>()
                    .Aggregate("", (current, temp) => current + imgfolder(file, temp));
                //StorageFile file = filelist.OfType<StorageFile>().First();
                //return await imgfolder(file);
            }

            return str;
        }