3#include <TargetConditionals.h>
5#import <Foundation/Foundation.h>
7#import <AppKit/AppKit.h>
16NSPasteboard* Board(
const std::string& name) {
18 return [NSPasteboard generalPasteboard];
21 pasteboardWithName:[NSString stringWithUTF8String:
name.c_str()]];
29 const std::string& pasteboard) {
31 NSPasteboard* board = Board(pasteboard);
32 NSData* data = [NSData dataWithBytes:png.data() length:png.size()];
33 [board clearContents];
34 if (![board setData:data forType:NSPasteboardTypePNG]) {
35 return absl::InternalError(
"The clipboard refused the PNG image");
38 return absl::OkStatus();
42 const std::string& pasteboard) {
44 NSPasteboard* board = Board(pasteboard);
45 NSData* data = [board dataForType:NSPasteboardTypePNG];
47 NSData* tiff = [board dataForType:NSPasteboardTypeTIFF];
49 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:tiff];
50 data = [rep representationUsingType:NSBitmapImageFileTypePNG
54 if (data == nil || data.length == 0) {
55 return absl::NotFoundError(
"The clipboard holds no image");
57 const auto* bytes =
static_cast<const uint8_t*
>(data.bytes);
58 return std::vector<uint8_t>(bytes, bytes + data.length);
67 return absl::UnimplementedError(
"Image clipboard is not available here");
71 return absl::UnimplementedError(
"Image clipboard is not available here");
PNG images on the system clipboard. SDL's clipboard is text-only.
absl::StatusOr< std::vector< uint8_t > > GetClipboardPng(const std::string &)
bool ImageClipboardSupported()
absl::Status SetClipboardPng(const std::vector< uint8_t > &, const std::string &)
Replaces the clipboard contents with one PNG image.