我在使用颜色的泛滥填充算法上取得了成功。
这是我一直在努力尝试填充颜色 但是没有成功填写图片。
填充颜色的代码
if (!_color)
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Please set fill color"
userInfo:nil];
CGColorRef colorRef = [_color CGColor];
const CGFloat *components = CGColorGetComponents(colorRef);
NSString* colorString = [NSString stringWithFormat:@"rgb(%f,%f,%f)", components[0]*255.0f,
components[1]*255.0f, components[2]*255.0f];
if (!PixelSetColor(fc_wand, [colorString UTF8String]))
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Unable to set wand color" userInfo:nil];
PixelIterator* iterator = NULL;
PixelWand** pixels = NULL;
size_t x;
iterator = NewPixelRegionIterator(magick_wand, _touchCoords.x*scale, _touchCoords.y*scale, 1, 1);
pixels = PixelGetNextIteratorRow(iterator,&x);
bc_wand = pixels[0];
channel = ParseChannelOption("rgba");
// The bordercolor=bc_wand (with fuzz of 20 applied) is replaced
// by the fill colour=fc_wand starting at the given coordinate - in this case 0,0.
// Normally the last argument is MagickFalse so that the colours are matched but
// if it is MagickTrue then it floodfills any pixel that does *not* match
// the target color
status = MagickFloodfillPaintImage(magick_wand, channel, fc_wand, _tolerance, bc_wand, _touchCoords.x*scale, _touchCoords.y*scale, MagickFalse);
if (status == MagickFalse) {
ThrowWandException(magick_wand);
}
size_t my_size;
unsigned char * my_image = MagickGetImageBlob(magick_wand,&my_size);
NSData* data = [[NSData alloc] initWithBytes:my_image length:my_size];
free(my_image);
UIImage* image = [[UIImage alloc] initWithData:data];
//[data release];
[self setImage:image];
//[image release];
if(_mwDelegate)
[_mwDelegate imageViewDidFinishedProcessing:self];
任何建议将不胜感激。带图案图像的颜色不起作用。