cocoa各种图片格式转换
来源:互联网 发布:汇率软件 编辑:程序博客网 时间:2024/05/21 07:10
具体下列格式png jpeg bmp gif tiff jpeg2000 pdf
PDF 要单独处理,其他的通过画图直接转即可。
1 画图 , 画一张红色图片
NSRect exportImageRect = NSZeroRect;
exportImageRect.size = NSMakeSize(100,100);
NSImage * result = [[[NSImage alloc] initWithSize:exportImageRect.size] autorelease];
[result lockFocus];
[[NSColor redColor] set];
[NSBezierPath fillRect:exportImageRect];
[result unlockFocus];
2,转换 除开pdf
,有些格式,对应的dictionary可以设置一些参数,压缩比什么的,gif的时长,一般的只用制定格式
- (void)saveImage:(NSImage *)image atPath:(NSString *)path {
NSBitmapImageRep *newRep = [NSBitmapImageRep imageRepWithData:image.TIFFRepresentation];
NSDictionary * properties = nil;
NSBitmapImageFileType type = NSPNGFileType;
if ([self.formatPopupButton.title isEqualToString:@"PNG"]) {
type = NSPNGFileType;
} else if ([self.formatPopupButton.title isEqualToString:@"JPEG"]) {
type = NSJPEGFileType;
properties = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
} else if ([self.formatPopupButton.title isEqualToString:@"BMP"]) {
type = NSBMPFileType;
} else if ([self.formatPopupButton.title isEqualToString:@"GIF"]) {
type = NSGIFFileType;
} else if ([self.formatPopupButton.title isEqualToString:@"TIFF"]) {
type = NSTIFFFileType;
} else if ([self.formatPopupButton.title isEqualToString:@"JPEG 2000"]) {
type = NSJPEG2000FileType;
}
NSData *pngData = [newRep representationUsingType:type properties:properties];
[pngData writeToFile:path atomically:YES];
}
3 ,转换成pdf
pdf一般是通过把图片设置到一个nsimageview控件里面,在从里面读pdf数据,然后写到文件
- (void)saveImageAsPDF:(NSImage *)image atPath:(NSString *)path {
NSRect frame = NSZeroRect;
frame.size = image.size;
NSImageView * imageView = [[[NSImageView alloc] initWithFrame:frame] autorelease];
[imageView setImage:image];
NSData * pdfData = [imageView dataWithPDFInsideRect:frame];
[pdfData writeToFile:path options:0 error:NULL];
}
- cocoa各种图片格式转换
- 转换图片格式
- 转换图片格式
- 图片格式转换
- 图片格式转换
- 图片格式转换
- 图片格式转换
- 图片格式转换
- 图片格式转换转换工具
- 各种图片格式详解
- 各种图片格式的对比
- 各种图片格式介绍
- 内存转换图片格式
- 使用cygwin转换图片格式
- 用DirectShow转换图片格式
- 图片格式转换工具制作
- ImageMagick 批量图片格式转换
- C#图片格式转换
- 解决百度网盘等软件无法联网但是浏览器可以上网的问题
- [精华] 初识Tornado:一个简单例子
- SecureCRT安装与使用
- 对元音个数进行统计,按下回车符退出
- poj 1082 Calendar Game 博弈递推
- cocoa各种图片格式转换
- PTA--双向链表模拟Deque
- AlertDialog最基本应用
- 远行
- android ScrollByScrollTo以及平移动画以及重新LayoutParams的区别
- Collection与Collections
- 【框架-MFC】获取当前鼠标的ICON图标(光标)
- Spring task quartz 定时任务的几种实现
- HDU5882——Balanced Game(2016年青岛区域赛网络赛)