I'm trying to convert multi-paged tif to pdf with following code: //took it from iphone magick sample
Code: Select all
- (void)posterizeImageWithoutCompression {
// WITHOUT JPEG COMPRESSION, work done by Karl: karl@xk72.com
NSLog(@"we're not using JPEG compression");
MagickWandGenesis();
magick_wand = NewMagickWand();
UIImage * src = [UIImage imageNamed:"ololo.tif"];
CGImageRef srcCGImage = [src CGImage];
NSData * srcData = (NSData *) CGDataProviderCopyData(CGImageGetDataProvider(srcCGImage));
unsigned long width = src.size.width;
unsigned long height = src.size.height;
const void *bytes = [srcData bytes];
const char *map;
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(srcCGImage);
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(srcCGImage);
if ((bitmapInfo & kCGBitmapByteOrder32Little) != 0)
switch (alphaInfo) {
case kCGImageAlphaLast:
case kCGImageAlphaPremultipliedLast:
map = "ABGR";
break;
case kCGImageAlphaFirst:
case kCGImageAlphaPremultipliedFirst:
map = "BGRA";
break;
case kCGImageAlphaNoneSkipLast:
map = "PBGR";
break;
case kCGImageAlphaNoneSkipFirst:
map = "BGRP";
break;
case kCGImageAlphaNone:
map = "BGR";
break;
}
else {
switch (alphaInfo) {
case kCGImageAlphaLast:
case kCGImageAlphaPremultipliedLast:
map = "RGBA";
break;
case kCGImageAlphaFirst:
case kCGImageAlphaPremultipliedFirst:
map = "ARGB";
break;
case kCGImageAlphaNoneSkipLast:
map = "RGBP";
break;
case kCGImageAlphaNoneSkipFirst:
map = "PRGB";
break;
case kCGImageAlphaNone:
map = "RGB";
break;
}
}
// ==================
// Here code fail in EXC_BAD_ACCESS when using something differente from UndefinedPixel
MagickBooleanType status = MagickConstituteImage(magick_wand, width, height, map, UndefinedPixel, bytes);
// ===================
if (status == MagickFalse) {
ThrowWandException(magick_wand);
}
MagickSetFormat(magick_wand, "pdf");
MagickSetImageDepth(magick_wand, 8);
NSString *root =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask , YES)
objectAtIndex:0];
const char * filename= [[root stringByAppendingFormat:@"text.pdf"] cStringUsingEncoding:NSUTF8StringEncoding];
status = MagickWriteImage(magick_wand, filename);
if (status == MagickFalse) {
ThrowWandException(magick_wand);
}
Trouble shooting:
- UIImage * src = [UIImage imageNamed:"ololo.tif"]; // reads only first page of tiff file @_@ Is exist other methods to get data without using uiimage class? Will [NSData dataWithContentOfFile] helps? If yes then from where i can get width/height of image and other properties?
- In my app i can receive a quite blob files(50-60 pages). Is imagemagick able to convert that kind of files in restricted memory size (near 25-30 mb)?
P.S. sorry for english