NSBitmapImageRepresentation image generation and saving resulting in image with much noise
NSBitmapImageRepresentation image generation and saving resulting in image with much noise
- Subject: NSBitmapImageRepresentation image generation and saving resulting in image with much noise
- From: Michael Robinson <email@hidden>
- Date: Mon, 09 Nov 2009 22:28:37 +1300
Hi List,
I'm attempting to create a bunch of png or jpg images based on user-set
options.
I'm getting images with a lot of noise in them, I was wondering if
anyone has any ideas why this would be? I've attached a screenshot of
the noisy images I've been getting. The shot is of four images that ....
well shouldn't have any noise at all.
Is there a common mistake that can cause these noisy images?
This is some of the code for generating images:
- (void)generateImage{
theImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:imageSize.width pixelsHigh:imageSize.height
bitsPerSample:8 samplesPerPixel:4
hasAlpha:YES isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0 bitsPerPixel:0];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:theImage]];
//create a path delineating the outline of the image
NSBezierPath *outlinePath = [self createOutlinePath];
//create a path delineating the border line - if no border then
this will be equal to the outline
if(hasBackgroundImage&& !drawBGImageOverBG){ //draw image below
gradient, background color
[self drawBGImage:outlinePath];
hasAnImage = YES;
}
if(hasBackgroundColor&& !cssOnly){ //if user wants a background
color and they don't want it with css
[self fillImageWithBGColor:outlinePath];
hasAnImage = YES;
}
if(hasGradient&& !cssOnly){
[self fillImageWithGradient:outlinePath];
hasAnImage = YES;
}
if(hasBackgroundImage&& drawBGImageOverBG){ //draw image above
gradient, background color
[self drawBGImage:outlinePath];
hasAnImage = YES;
}
//Draw border... if the user wants one
if(!cssOnly){
[self drawBorder]; //border is created then painted onto
theImage
hasAnImage = YES;
}
[NSGraphicsContext restoreGraphicsState];
}
Saving is done like:
- (NSString *)saveImage:(NSString*)dir:(NSString*)pageID:(NSString *)name{
NSData *data = [NSData alloc];
if(fileType == FILETYPE_PNG){
data = [theImage representationUsingType:NSPNGFileType
properties:nil];
fileName = [NSString stringWithFormat:@"%@_%@.png", name, pageID];
}
else if(fileType == FILETYPE_JPG){
data = [theImage representationUsingType:NSJPEGFileType
properties:nil];
fileName = [NSString stringWithFormat:@"%@_%@.jpg", name, pageID];
}
[data writeToFile:[NSString stringWithFormat:@"%@/%@", dir,
fileName] atomically:NO];
return fileName;
}
This is part of a class that is instantiated once per image - should I
be doing something to ... clear a whatchamacall it or clean a thingameejig?
The first image that's created is OK, subsequent ones are not.
Is something being held back in memory maybe, spraying itself rudely
into each image?
Thanks list,
Mike
Attachment:
noisy_images.jpg
Description: JPEG image
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden