2012-08-03 5 views
2

간단한 UIImage를 BitmapContext로 변환하고 싶습니다만, UIImage를 BitmapContext로 변환하는 튜토리얼을 찾을 수 없습니다. 친절하게 말해 어떻게해야합니까?UIImage에서 BitmapContext로

감사합니다.

+1

당신의 노력이 될 수 있습니까? – QueueOverFlow

답변

1

이 코드 도움을 당신에게

CGSize newSize = CGSizeMake(320, 400); 
UIGraphicsBeginImageContext(newSize); 

[imageView.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 



UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

NSData * data = UIImagePNGRepresentation(newImage); 
[data writeToFile:@"foo.png" atomically:YES]; 


UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);///save image in phone 

OR For Bitmap. 

CGContextRelease(context); 
context = CGBitmapContextCreate (NULL,              
           image.size.width, 
           image.size.height, 
           8, // bits per component 
           bitmapBytesPerRow, 
           colorSpace, 
           kCGImageAlphaLast 
           ); 
CGColorSpaceRelease(colorSpace);                  

CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage); 
pixelData = CGBitmapContextGetData(context); 
+0

안녕하세요, UIImage를 BitmapContext로 변환하고 화면에 그려야합니다. 앨범에 저장하고 싶지 않습니다. – Smith

+0

픽셀 데이터 란 무엇입니까? 그 유형은 무엇입니까? – Smith

+2

다음 링크를 확인하십시오. http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGBitmapContext/Reference/reference.html#//apple_ref/c/func/CGBitmapContextCreate – QueueOverFlow

관련 문제