I'm new to ImageMagick library, and my client want some of its functions in iOS application.
He gave me an image processing code: convert IMG.JPG -virtual-pixel gray -distort Barrel "0.4 0.0 0.0 0.4" IMG_BAREL.PNG
Now, I have to replicate that on iPhone. Here and there, I've managed to do something, but not a whole thing. Can you help me?
My method is here:
Code: Select all
- (void)convertAndDistort:(UIImage *)sourceImage
{
// Instantiate MagickWand-a
MagickWandGenesis();
magick_wand = NewMagickWand();
// Get image as BLOB in MagickWand
NSData *dataObject = UIImagePNGRepresentation(sourceImage);
MagickBooleanType status;
status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]); // U MagickWand 'ubacujemo' BLOB objekat
if (status == MagickFalse) {
ThrowWandException(magick_wand);
}
// Distort image
const double controlPoints[4] = {0.4, 0.0, 0.0, 0.4};
const size_t q = 4;
status = MagickDistortImage(magick_wand, BarrelDistortion, q, controlPoints, MagickFalse);
if (status == MagickFalse) {
ThrowWandException(magick_wand);
}
// Take BLOB from MagickWand
size_t length;
unsigned char *imageBytes = MagickGetImageBlob(magick_wand, &length);
NSData *data = [[NSData alloc] initWithBytes:imageBytes length:length];
free(imageBytes);
// Destroy MagickWand
magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
// Set image on button
UIImage *image = [[UIImage alloc] initWithData:data];
[data release];
[imageViewButton setImage:image forState:UIControlStateNormal];
[image release];
}
-distort Barrel "0.4 0.0 0.0 0.4"
But how can I do the first part?
convert IMG.JPG -virtual-pixel gray
How to set everything to gray, except that 'barel piece' of image?
Thanks!