0
我從網上下載.jpg文件與此代碼:如何將NSMutableData轉換爲視圖中的圖像?
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://cvcl.mit.edu/hybrid/cat2.jpg"]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
receivedData=[[NSMutableData data] retain]; // etc etc
,一切工作正常。我只是不知道如何處理數據。假設我在IB創建了一個圖像視圖,我將如何去顯示圖像?下面是最後一位:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// ******do something with the data*********...but how
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
// release the connection, and the data object
[connection release];
[receivedData release];
}
如果你在Mac上需要這個,使用NSImage的initWithData:方法。 – 2009-07-25 00:58:06