gpt4 book ai didi

objective-c - 将 UIImage 转换为 tiff/tif 文件

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:56 25 4
gpt4 key购买 nike

在我的 iPhone 应用程序中,我需要将 UIImage 转换为 tiff/tif 文件,以便使用 tif 类型的参数调用一些 API。所以我应该从 iphone 照片库获取 UIImage 或从相机拍摄照片。请让我知道这种转换(UIImage 到 tif/tiff)是否可行,如果可能,最好的方法是什么。提前致谢。

最佳答案

NSLog(@"I am using MagicWand Library");
//GIT path https://github.com/marforic/imagemagick_lib_iphone

MagickWandGenesis();
magick_wand = NewMagickWand();
MagickSetFormat(magick_wand, "tiff");
//NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"daftpunk.jpg"]);
NSData * dataObject = UIImageJPEGRepresentation([UIImage imageNamed:@"daftpunk.jpg"], 1.0);
//UIImageJPEGRepresentation([imageViewButton imageForState:UIControlStateNormal], 90);
MagickBooleanType status;
status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
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);
magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
UIImage * image = [[UIImage alloc] initWithData:data];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"DAFTPUNK.tif"]; //Add the file name
[data writeToFile:filePath atomically:YES];

[imageViewButton setImage:image forState:UIControlStateNormal];

关于objective-c - 将 UIImage 转换为 tiff/tif 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11969813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com