2013-05-30 69 views
0

I使用AES算法對圖像進行加密。當我在IKImageBrowserView中使用這些圖像時,它會正確顯示圖像,但我無法將圖像拖放到粘貼板。 我已經設置圖像表示對IKImageBrowserView圖像對象這樣拖放不在IKImageBrowserView中工作

- (NSString *) imageRepresentationType 
{ 
    return IKImageBrowserNSDataRepresentationType; 
} 
- (id) imageRepresentation 
{ 
    return [[NSData dataWithContentsOfFile:path]decryptWithString:PASS]; 
} 

但它的工作時,我給這樣的

- (NSString *) imageRepresentationType 
{ 
    return IKImageBrowserPathRepresentationType; 
} 

- (id) imageRepresentation 
{ 
    return path; 
} 

上面的代碼工作,因爲當我從IKImageBrowserView拖動圖像將返回 圖像的路徑。

現在我需要做的是將IKImageBrowserView中的加密圖像拖放到Pasteboard。

回答

0

終於我明白了。

對於非文件路徑來表示圖像,我們需要實現 - imageBrowser:writeItemsAtIndexes:toPasteboard:

- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard: (NSPasteboard *)pasteboard 
{ 
     NSUinteger index; 

     //instantiate an array to store paths 
     filesArray = [NSMutableArray array]; 

     //for each index... 
for(index = [itemIndexes firstIndex]; index != NSNotFound; index = [itemIndexes indexGreaterThanIndex:index]){ 

       //...get the path you want to add to the pasteboard 
       id myDatasourceItem = [_myDatasourceArray objectAtIndex:index]; 
       NSString *path = [myDatasourceItem myLargeImageFilePath]; 

       //add it to your array 
       [filesArray addObject:path]; 
     } 

     //declare the pasteboard will contain paths 
[pasteboard declareTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,nil] owner:self]; 

     //set the paths 
[pasteboard setPropertyList:filesArray forType:NSFilenamesPboardType]; 

     //return the number of items added to the pasteboard 
     return [filesArray count]; 
}