Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying Images to the UIPasteboard

Tags:

iphone

How can one copy images to the UIPasteboard?

I have only seen examples for text.

like image 385
some_id Avatar asked Feb 24 '11 22:02

some_id


2 Answers

If you look at Apple's Documentation for UIPasteboard, you see that you can use the 'setImage:` method to copy images to the pasteboard, eg:

[[UIPasteboard generalPasteboard] setImage:myImage];

or if you want to add multiple images:

[[UIPasteboard generalPasteboard] setImages:[NSArray arrayWithObjects:myFirstImage, mySecondImage, nil]];

or if you already have the array of images:

[[UIPasteboard generalPasteboard] setImages:myImagesArray];

(where all the above variables that begin with my should be substituted for the ones in your code)

like image 71
Jonathan. Avatar answered Oct 06 '22 23:10

Jonathan.


use this ..... here newImage is UIImage.

UIPasteboard *pasteBoard = [UIPasteboard pasteboardWithName:UIPasteboardNameGeneral create:NO];
pasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation(newImage);
[pasteBoard setData:data forPasteboardType:(NSString *)kUTTypePNG];     
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:00"]];
like image 34
Vijay Avatar answered Oct 06 '22 23:10

Vijay