I want to show pasteboard content in an UIImageview
if pasteboard contains image.
How can I do it? I tried with UIPasteboard
, but how can I check which type of image it contains?
I want to show pasteboard content in an UIImageview
if pasteboard contains image.
How can I do it? I tried with UIPasteboard
, but how can I check which type of image it contains?
You don't need the type of data to show the image, just do:
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyPaste" create:YES];
NSData *data = [appPasteBoard dataForPasteboardType:@"com.yourCompany.yourApp.yourType"];
imageView.image = [UIImage imageWithData:data];
However, you could guess the type by looking at the first byte (source):
+ (NSString *)contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
}
return nil;
}