{"id":22454339,"url":"https://github.com/clowd/clowd.clipboard","last_synced_at":"2026-03-03T06:31:20.269Z","repository":{"id":43782176,"uuid":"351212553","full_name":"clowd/Clowd.Clipboard","owner":"clowd","description":"A platform-agnostic clipboard library for dotnet, and a bespoke dib parser.","archived":false,"fork":false,"pushed_at":"2022-10-23T15:48:11.000Z","size":1612,"stargazers_count":23,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-21T09:15:49.662Z","etag":null,"topics":["avalonia","avaloniaui","bitmap","clipboard","gdi","parser","windows","winforms","wpf"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clowd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"caesay","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2021-03-24T20:21:24.000Z","updated_at":"2024-08-18T14:29:36.000Z","dependencies_parsed_at":"2023-01-20T07:34:17.227Z","dependency_job_id":null,"html_url":"https://github.com/clowd/Clowd.Clipboard","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowd%2FClowd.Clipboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowd%2FClowd.Clipboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowd%2FClowd.Clipboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowd%2FClowd.Clipboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clowd","download_url":"https://codeload.github.com/clowd/Clowd.Clipboard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228426122,"owners_count":17917790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avalonia","avaloniaui","bitmap","clipboard","gdi","parser","windows","winforms","wpf"],"created_at":"2024-12-06T07:07:31.345Z","updated_at":"2026-03-03T06:31:20.226Z","avatar_url":"https://github.com/clowd.png","language":"C#","funding_links":["https://github.com/sponsors/caesay"],"categories":[],"sub_categories":[],"readme":"\r\n\r\n# Clowd.Clipboard\r\nThis library is a light-weight clipboard replacement library for dotnet. It is not tightly coupled to a UI framework, and it contains a [custom bitmap parser](#clowdclipboardbitmaps) to help deal with some of the inconsistencies which are present in clipboard images.\r\n\r\nJoin us on Discord: [![Discord](https://img.shields.io/discord/767856501477343282?style=flat-square\u0026color=purple)](https://discord.gg/M6he8ZPAAJ)\r\n\r\n\r\n\r\n| **Package**                                                  | **Nuget**                                                    | **Notes**                                                    |\r\n| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |\r\n| [Clowd.Clipboard](https://www.nuget.org/packages/Clowd.Clipboard) | [![Nuget](https://img.shields.io/nuget/v/Clowd.Clipboard?style=flat-square)](https://www.nuget.org/packages/Clowd.Clipboard/) | Core library containing basic clipboard functionality. No image/bitmap support. |\r\n| [Clowd.Clipboard.Gdi](https://www.nuget.org/packages/Clowd.Clipboard.Gdi) | [![Nuget](https://img.shields.io/nuget/v/Clowd.Clipboard.Gdi?style=flat-square)](https://www.nuget.org/packages/Clowd.Clipboard.Gdi/) | Adds `ClipboardGdi`, images using `System.Drawing.Bitmap`.   |\r\n| [Clowd.Clipboard.Wpf](https://www.nuget.org/packages/Clowd.Clipboard.Wpf) | [![Nuget](https://img.shields.io/nuget/v/Clowd.Clipboard.Wpf?style=flat-square)](https://www.nuget.org/packages/Clowd.Clipboard.Wpf/) | Adds `ClipboardWpf`, images using `System.Windows.Media.Imaging.BitmapSource`. |\r\n| [Clowd.Clipboard.Avalonia](https://www.nuget.org/packages/Clowd.Clipboard.Avalonia) | [![Nuget](https://img.shields.io/nuget/v/Clowd.Clipboard.Avalonia?style=flat-square)](https://www.nuget.org/packages/Clowd.Clipboard.Avalonia/) | Adds `ClipboardAvalonia`, images using `Avalonia.Media.Imaging.Bitmap`. |\r\n\r\n\r\n\r\n## Clipboard Examples\r\n\r\nBelow are several examples of how to do clipboard operations.\r\n\r\n\r\n\r\n### Getting or setting simple types (single operation)\r\n\r\nThe static helper (eg. `ClipboardWpf` or `ClipboardGdi`) has methods for simple things. This takes care of opening the clipboard, reading the data, and then disposing the handle.\r\n\r\n```cs\r\n// get text on clipboard\r\nstring clipboardText = await ClipboardWpf.GetTextAsync();\r\n\r\n// get image on clipboard\r\nBitmapSource clipboardImg = await ClipboardWpf.GetImageAsync();\r\n\r\n// set image on clipboard (this clears what was previously on clipboard)\r\nClipboardWpf.SetImage(clipboardImg);\r\n```\r\n\r\n\r\n\r\n### Getting or setting complex types (multi operation)\r\n\r\nYou should not use the static helper methods if you need to perform several clipboard operations. If you need to read or set multiple formats at once, or check for what formats are available, you should instead open a clipboard handle and dispose it when you're done.\r\n\r\n```cs\r\nBitmapSource clipImage;\r\nstring clipText;\r\n\r\nusing (var handle = await ClipboardWpf.OpenAsync());\r\n{\r\n    if (handle.ContainsText()) \r\n    {\r\n        clipText = handle.GetText();\r\n    }\r\n    \r\n    if (handle.ContainsImage())\r\n    {\r\n        clipImage = handle.GetImage();\r\n    }\r\n}\r\n```\r\n\r\n\r\n\r\n### Reading list of currently available clipboard formats\r\n\r\n```cs\r\nusing (var handle = await ClipboardWpf.OpenAsync());\r\n{\r\n    Console.WriteLine(\"Formats currently on the clipboard: \");\r\n    foreach (var f in handle.GetPresentFormats())\r\n        Console.WriteLine(\" - \" + f.Name);\r\n}\r\n```\r\n\r\n\r\n\r\n### Using custom clipboard formats\r\n\r\nUsing a custom/application specific format is very easy with this library. You should first register your format somewhere statically in your application.\r\n\r\n```cs\r\n// a custom format stored on the clipboard as UTF-8. \r\n// the name chosen for the format should be globally unique, so consider\r\n// using a guid if you do not intend to share with other applications.\r\nprivate static readonly ClipboardFormat\u003cstring\u003e myCustomTextFormat \r\n    = ClipboardFormat.CreateCustomFormat(\"MyGloballyUniqueFormatId\", new TextUtf8());\r\n\r\n// a custom format for storing binary data\r\nprivate static readonly ClipboardFormat myCustomBinaryFormat \r\n    = ClipboardFormat.CreateCustomFormat(\"MyGloballyUniqueFormatId_2\");\r\n```\r\n\r\nOnce your clipboard format is registered, you can use it the same way as any built-in format.\r\n\r\n```csharp\r\n// set custom data to clipboard\r\nusing (var handle = await ClipboardWpf.OpenAsync())\r\n{\r\n    // it is possible to set multiple items to the clipboard.\r\n    handle.SetFormat(myCustomTextFormat, \"My Custom Text\");\r\n    handle.SetFormat(myCustomBinaryFormat, new byte[0]);\r\n\r\n    // this is a common \"built-in\" specific format not covered by the simple functions such as \"GetText\".\r\n    handle.SetFormat(ClipboardFormat.Html, \"\u003chtml\u003eSome Html to share with other applications\u003c/html\u003e\");\r\n}\r\n\r\n// later, read custom data from clipboard\r\nusing (var handle = await ClipboardWpf.OpenAsync())\r\n{\r\n    if (handle.ContainsFormat(myCustomTextFormat)) \r\n    {\r\n        string myCustomText = handle.GetFormatType(myCustomTextFormat);\r\n    }\r\n    if (handle.ContainsFormat(myCustomBinaryFormat)) \r\n    {\r\n    \tbyte[] myCustomBytes = handle.GetFormatBytes(myCustomBinaryFormat);  \r\n    }\r\n}\r\n```\r\n\r\n**Note:** you can use `CreateCustomFormat(string formatName)` to read data added to the clipboard by other windows applications. You can provide your own `IDataConverter\u003cT\u003e` if you wish to automatically translate this to a dotnet type using the `GetFormatType` method, or you can retrieve the data as a `byte[]` with the `GetFormatBytes` method.\r\n\r\n\r\n\r\n# Clowd.Clipboard.Bitmaps\r\n\r\nThe purpose of this library is to attempt to create a more robust BMP/DIB parser than currently exists in WPF or in System.Drawing (GDI+). It's purpose is to provide good interop with packed dibs on the Windows Clipboard, which WPF and GDI do not support.\r\n\r\nThere are two big barriers to reading Bitmap's on the clipboard; Both `CF_DIB` and `CF_DIBV5` are available, but they lack `BITMAPFILEHEADER`'s. Additionally, WPF and GDI do not support the `BITMAPV5HEADER` present in `CF_DIBV5` and therefore can not properly read transparency data. This library has been tested with a variety of weird, rare, invalid bitmap files and supports every bitmap reference file I could come across - including rare reader formats (like OS2v1, OS2v2) and rare compression algorithms like RLE and Huffman1D.\r\n\r\nThis library may play better with bitmaps written to the clipboard by native applications than GDI or WPF can manage.\r\n\r\n### Bitmap Known Limitations / Issues\r\n - Bitmap data will be translated to sRGB if calibration data and/or a embedded ICC color profile exists in the bitmap file. This was done by design, because color profile support in WPF and GDI is limited. This library does not support writing a color profile.\r\n - Not all pixel formats are supported natively, some are converted to Bgra32 when parsing\r\n - Does not support Gray colorspace bitmaps\r\n\r\n### Bitmap Example\r\nThere is a convenient to use wrapper for both GDI and WPF, depending on your choice of UI technology.\r\n```cs\r\nbyte[] imageBytes = File.ReadAllBytes(\"file.bmp\");\r\nBitmapSource bitmap = BitmapWpf.FromBytes(imageBytes, BitmapWpfReaderFlags.PreserveInvalidAlphaChannel);\r\n\r\n// profit!\r\nbyte[] imageBytes2 = BitmapWpf.ToBytes(bitmap);\r\n```\r\n\r\n### Bitmap Compatibility\r\n\r\n - :heavy_check_mark: Files with or without a `BITMAPFILEHEADER`\r\n - :heavy_check_mark: Files with any known BMP header format, including WindowsV1, V2, V3, V4, V5, OS2v1, OS2v2\r\n - :heavy_check_mark: Files with logical color space / calibration data\r\n - :heavy_check_mark: Files with embedded ICC color formats\r\n - :heavy_check_mark: Files with any valid compression format, including RGB, BITFIELDS, ALPHABITFIELDS, JPEG, PNG, HUFFMAN1D (G31D), RLE4/8/24\r\n - :heavy_check_mark: Files with completely non-standard pixel layout (for example, 32bpp with the following layout: 7B-25G-0R-0A)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclowd%2Fclowd.clipboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclowd%2Fclowd.clipboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclowd%2Fclowd.clipboard/lists"}