开发者

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

开发者 https://www.devze.com 2023-03-21 07:03 出处:网络
I have an image that I append a message to inside the NSData of the image and then save it to the p开发者_如何学Choto library using ALAssetLibrary. I then send it to someone over email.

I have an image that I append a message to inside the NSData of the image and then save it to the p开发者_如何学Choto 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?


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消