我对 UIKit 和 Core Graphics 之间的坐标系差异有点困惑。Apple 文档指出 UIKit 使用 ULO(左上原点),而 Core Graphics 使用 LLO(左下原点)。
然而,正如一篇关于坐标系的文章中所指出的,值得注意的是 UIKit
在调用 -drawRect 之前有用地翻转坐标系:
当我在 (0,0) 处绘制一个矩形时,它确实位于左上角,所以事情看起来确实翻转了。但是,当我使用 CGContextDrawImage() 绘制图像时,它仍然是翻转的。我知道我可以使用 drawAtPoint() 来避免颠倒的图像,但我只是对坐标系感到好奇:如果它是由 UIKit 翻转的,那么如果将其绘制到翻转的上下文中,为什么图像仍然是颠倒的?另外,有没有办法获得未翻转的坐标系?也就是说,有没有一种方法可以不通过UIKit来创建CGContext?
谢谢!
我正在尝试添加旋转相机功能,AVFoundation以允许用户在前置摄像头和后置摄像头之间切换.
如下面的代码所示,我已经添加了一些println()语句,并且所有值看起来都是合法的,但在测试时代码总是会丢失到失败的else子句CanAddInput().
我已经试过sessionPreset(这是在预先初始化会话另一个功能)设置为不同的值,包括AVCaptureSessionPresetHigh和AVCaptureSessionPresetLow,但没有帮助.
@IBAction func rotateCameraPressed(sender: AnyObject) {
// Loop through all the capture devices to find right ones
var backCameraDevice : AVCaptureDevice?
var frontCameraDevice : AVCaptureDevice?
let devices = AVCaptureDevice.devices()
for device in devices {
// Make sure this particular device supports video
if (device.hasMediaType(AVMediaTypeVideo)) {
// Define devices
if (device.position == AVCaptureDevicePosition.Back) {
backCameraDevice = device as? AVCaptureDevice
} else if (device.position == AVCaptureDevicePosition.Front) {
frontCameraDevice = device …Run Code Online (Sandbox Code Playgroud) 在Python 2.7解释器中,字符串拆分函数按预期工作:
>>> import string
>>> a = "a b c"
>>> string.split(a)
['a', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)
但是,在Python 3.4.1解释器中,我收到一个错误:
>>> import string
>>> a = "a b c"
>>> string.split(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'split'
Run Code Online (Sandbox Code Playgroud)
知道我在这里缺少什么吗?
谢谢!