SolidSnake4444
SolidSnake4444

Reputation: 3587

iPhone, how does one read an image from the UIPasteboard as NSData?

I have an image that I append a message to inside the NSData of the image and then save it to the photo library using ALAssetLibrary. I then send it to someone over email.

I want to give the user the option to press and hold a modified image and then press copy and paste it in my app. To do this my app would have to read the image that was copied either byte by byte to get the whole file (preferred method) or read the whole thing as an NSData.

How would I be able to read the general pasteboard's contents as NSData or byte for byte on a buffer?

Upvotes: 0

Views: 1589

Answers (2)

Caleb
Caleb

Reputation: 125007

Did you look at the documentation for UIPasteboard? The first thing that jumps out at me is:

- (NSData *)dataForPasteboardType:(NSString *)pasteboardType

Upvotes: 1

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

You could use the below code to read the image data from UIPasteboard .

UIPasteboard * pasteBoard = [UIPasteboard pasteboardWithName:@"CopyFrom" create:YES];
NSData *data = [pasteBoard dataForPasteboardType:@"com.appshop.copyfrom.imagedata"];
imageView.image = [UIImage imageWithData:data];

for more check blog posts.

How to Use UIPasteBoard to Implement Custom Copy and Paste In Your App

Upvotes: 1

Related Questions