tags:

views:

43

answers:

1

How to convert CFDataRef into NSData ?

I have CFDataRef and I want to convert it into NSData. I am not getting how to do this.

anyone help me..

CGDataProviderRef dataProvider = CGImageGetDataProvider(screenShot); CFDataRef data = CGDataProviderCopyData(dataProvider); CGDataProviderRelease(dataProvider); NSString *imagePathLocation = [destinationPath stringByAppendingString:[@"/" stringByAppendingString:DesktopImage]]; [[NSFileManager defaultManager]createFileAtPath: imagePathLocation contents:nil attributes:nil]; fileHandleForImage = [NSFileHandle fileHandleForWritingAtPath:imagePathLocation]; NSData * data1 = (NSData *)data; [fileHandleForImage writeData:data1];

When I typecast(NSData * data1 = (NSData *)data) it Image get corrupted.

A: 

It's toll-free bridged, so you just have to cast it.

NSData *myData = (NSData *)myCFDataRef;
Robot K
yes its CFDataRef, I am sorry. I want to save CGImage.
Greshi Gupta