2009-07-25 4 views
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]; 
} 

답변

1

있는 UIImage가있는 방법 + imageWithData :

+0

그리고 당신은 Mac에서이 필요한 경우, NSImage의 initWithData 사용 방법. –

+0

예 .. 우스, 맥 질문 이었나요? 나는 너무 오랫동안 프로그래밍 해왔다. :) – mjhoy

+0

그것이 Mac이나 iPhone의 질문인지는 알 수 없다. –

2

가정 당신의 NSImageView는 수신 된 데이터를 사용하여 이미지를 초기화 할 수 있어야한다 imageView라는 IBOutlet로 첨부 한 다음 이미지를 설정 보기를 눌러 이미지를 표시합니다.

NSImage *image = [[NSImage alloc] initWithData:receivedData]; 
[imageView setImage:image]; 
[image release]; 
관련 문제