Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy UIImage data to clipboard/UIPasteboard? And how do I test it?

I tried to use the following code to copy the Image data to UIPasteboard on click of the Copy item in the menu.

UIPasteboard *gpBoard = [UIPasteboard generalPasteboard];
[[gpBoard setData:UIImageJPEGRepresentation(imgView.image, 1.0) forPasteboardType:UIPasteboardTypeListImage];

Which parameter i have to send for forPasteboardType:, and how to test after copying the data?

like image 389
pradeepa Avatar asked Jul 11 '11 06:07

pradeepa


People also ask

How do I copy UIImage?

Deep copying UIImage *newImage = [UIImage imageWithData:UIImagePNGRepresentation(oldImage)]; This will copy the data but will require setting the orientation property before handing it to something like UIImageView for proper display. Another way to deep copy would be to draw into the context and grab the result.

What is pasteboard on Iphone?

by John E Dunn. To most iOS users, pasteboard is simply part of the way to copy and paste data from one place to another. You take a picture, fancy sharing it with friends, and your phone uses the pasteboard to move the image to the desired app.

What is Uipasteboard?

An object that helps a user share data from one place to another within your app, and from your app to other apps.

How do you clear a Uipasteboard?

If you know that your program is the only one manipulating the specific pasteboard, then yes, setting the string property to "" will effectively clear the pasteboard.


1 Answers

It's a lot easier:

[UIPasteboard generalPasteboard].image = imgView.image;

To get the image out again:

UIImage *image = [UIPasteboard generalPasteboard].image;
like image 152
omz Avatar answered Sep 30 '22 16:09

omz