CGContextDrawImage画图
来源:互联网 发布:在淘宝上怎么注册店铺 编辑:程序博客网 时间:2024/04/29 20:29
描述一下,这两天用到了,CGContextDrawImage 这个函数,在重写我的drawrect函数的时候,我要在某个地方画一个图。然后画嘛~刚开始也没注意,后来发现图画倒了。按照正常程序员的思路,画布的坐标是从屏幕的左上开始!!为了不误导别人,我把上面那句划掉。
然后找原因,在官方文档中找到了原因!
Cocoa和Quartz用的是基础坐标系!左下 是我们所谓的原点!具体参见官方文档。下面参考链接2
废话不说,直接上图!
怎么办!
下面说解决办法!
1) get the current graphics context;
2) translate and flip the coordinate system;
3) transform the drawing rectangle;
具体代码
CGContextSaveGState(context);//入栈 CGContextTranslateCTM(context, rect.origin.x, rect.origin.y); CGContextTranslateCTM(context, 0, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y); CGContextDrawImage(context, rect, image); CGContextRestoreGState(context);//出栈
这样图就调过来了!
参考链接:http://blog.ddg.com/?p=10A;https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html
- CGContextDrawImage画图
- CGContextDrawImage画图图形相反 镜像
- 讨论CGContextDrawImage
- CGContextDrawImage使用和分析
- 使用CGContextDrawImage绘制图片上下颠倒
- 使用CGContextDrawImage绘制图片上下颠倒解决方法
- 画图:
- 画图
- 画图
- 画图
- 画图
- 画图
- 画图
- 画图
- 画图
- 画图
- 画图
- 画图
- hdu 2063 过山车
- 让作者告诉你DirectX修复工具到底能解决什么问题
- Linux 分区命名
- 工作笔记整理
- Fusion Charts导出图片或Pdf
- CGContextDrawImage画图
- UML用例图之泛化(generalization)、扩展(extend)和包含(include)关系--UML一波流系列讲解
- RHEL安装Hyper-V集成服务后无法使用光驱的解决方法
- nfs:server is not responding,still trying 解决
- awk实例
- 如何让eclipse和glassfish结合使用
- 很完整的2、8、10、16进制转换方法的进制的转化
- Color depth
- symantec NBU with status 59: access to the client was not allowed