圧縮データをCGImageRefから取得して、ネットワーク接続経由で送信したいと考えています。 これを行うには、CGImageDestinationRef(CGImageDestinationCreateWithData)を使用します。CGImageDestinationを圧縮したCGImageをバイトを取得した後に切り捨てました
CFDataRefオブジェクトからデータを引き出した後、画像の下部に2行が表示されません。ここで
は(...目的を読み取るための洗浄)私は何をすべきかです:CFImageRef image = getTheImageRefIWant();
CFMutableDataRef pngData = CFDataCreateMutable (kCFAllocatorDefault, 0);
CGImageDestinationRef dataDest = CGImageDestinationCreateWithData (pngData, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage (dataDest, image, NULL); //also tried this with options...
CGImageDestinationFinalize (dataDest);
CFIndex len = CFDataGetLength(pngData);
//copy data
unsigned char* m_image = malloc(len);
CFDataGetBytes (pngData, CFRangeMake(0,len), m_image);
//save data - for testing purpose
FILE *file = fopen("/path/test.png", "wb");
fwrite(m_image, 1, len, file);
//adding header and stuff - skipped here...
//send data
send(sockfd, m_image, len, 0);
私はNSDataオブジェクトとしてCFDataオブジェクトを使用してディスクに保存した場合はそれはありません作品:
NSData *data = [(NSData *)pngData autorelease];
[data writeToFile:@"/path/test.png" atomically:YES];
しかしNSDatasバイトメソッドを使用している場合、それは同じ(切り捨て画像)です:
NSUInteger len = [data length];
m_image = malloc(len);
memcpy(m_image, (unsigned char*)[data bytes], len);
がCFDataオブジェクト内のデータが思えるようだがそれは大丈夫です。 しかしバイトを正しく取得するには?
ありがとうございました。
CGImageDestinationRefがリークしています。 'CFRelease(dataDest)'を追加してください。場合によっては、これは完全なコードのリストです:) – Buzzy