I'm trying to save an NSBitmapImageRep initialized with - initWithCGImage: onto a disk.

But the image of the saved file is bad. This means only black and white horizontal lines are drawn meaninglessly.

The _rep in the below code is the NSBitmapImageRep instance allocated and initialized with -initWithCGImage: as I said at the beginning,
and the image rep has alpha.

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSDictionary* properties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat:0.7], NSImageCompressionFactor, [NSNumber numberWithBool:YES], NSImageProgressive, nil];
        
NSData* result = [_rep representationUsingType:NSJPEGFileType properties:properties];
   return result;
}

The NSBitmapImageRep is logged like the following:
0x15ce70 Size={400, 264} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=400x264 Alpha=YES Planar=NO Format=2

Would you tell me what I'm missing?

Thank you for reading this message.

Instead of taking the CGImage into NSImage and then exporting the NSImage, you might just use ImageIO to save the CGImage directly. Look up CGImageDestination in the documentation and see if you get better results using it to export as JPEG.

Scott

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to