2015-06-29 38 views

回答

0

你不需要的數據類型來顯示圖像,只是做:

+ (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; 
} 

UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:@"CopyPaste" create:YES]; 
NSData *data = [appPasteBoard dataForPasteboardType:@"com.yourCompany.yourApp.yourType"]; 
imageView.image = [UIImage imageWithData:data]; 

但是,你可以通過查看第一個字節(source)猜類型

+0

你爲什麼不只用這個? 'let image = UIPasteboard.generalPasteboard()。image! let data = UIImagePNGRepresentation(image)' –

相關問題