iOS 10.2 swift 3.0
我正在使用这些例程剪切,调整大小并重新组合图像以在AppleTV上显示。但是,尽管它将图像报告为正确的尺寸,但它并没有像我预期的那样工作。
我在这里想念的是什么?
func cropImage(image: UIImage, newRect: CGRect) -> UIImage {
let img = CIImage(image: image)!.cropping(to: newRect)
let image = UIImage(ciImage: img, scale: 1.0, orientation: image.imageOrientation)
return image
}
func combine2LONGImage(imageUn: UIImage, imageDeux: UIImage) -> UIImage {
let size = CGSize(width: imageUn.size.width + imageDeux.size.width, height: imageUn.size.height)
UIGraphicsBeginImageContext(size)
imageUn.draw(in: CGRect(x: 0, y: 0, width: imageUn.size.width, height: imageUn.size.height))
imageDeux.draw(in: CGRect(x: imageUn.size.width, y: 0, width: imageDeux.size.width, height: imageDeux.size.height))
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}
func resizeLONGImage(image: UIImage, newSize: CGSize) -> UIImage {
UIGraphicsBeginImageContext(newSize)
image.draw(in: CGRect(x:0, y:0, width: newSize.width, height: self.view.bounds.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
let leftSide = CGRect(x: 0, y: 0, width: (image2S?.size.width)!/2, height: self.view.bounds.height)
let leftImage = self.cropImage(image: image2S!, newRect: leftSide)
let rightSide = CGRect(x: (image2S?.size.width)!/2, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
let rightImage = self.cropImage(image: image2S!, newRect: rightSide)
print("20022017 \(leftImage) \(rightImage)")
let newLeftImage = self.resizeLONGImage(image: leftImage, newSize: CGSize(width: self.view.bounds.width, height: self.view.bounds.height))
let newRightImage = self.resizeLONGImage(image: rightImage, newSize: CGSize(width: self.view.bounds.width, height: self.view.bounds.height))
let superNewImage = self.combine2LONGImage(imageUn: newLeftImage, imageDeux: newRightImage)
print("19022017 newimage \(self.image2P.bounds) \(leftImage.size.width) \(newLeftImage.size.height) \(superNewImage.size)")
self.image2P.image = superNewImage
self.image2P.contentMode = .left
self.image2P.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
返回的图像是[正确的尺寸[AppleTV屏幕的两倍,相同的高度] ...但contentMode
使我失望,它调整了图像大小,使其适合屏幕!]。我做了一个快照,我得到了这个......
是的,这是3& 4,但它与1& 1相同。 2。
控制台正在报告?
19022017 previewPane 1920.0 1080.0 1920.0 1080.0
20022017 Optional(<UIImage: 0x60000009d9c0>, {1920, 768}) Optional(<UIImage: 0x60000009da10>, {1024, 768})
19022017 newimage (0.0, 0.0, 1920.0, 1080.0) 1920.0 1080.0 (3840.0, 1080.0)
superNewImage
是3840宽和1080高,我说左边是正确的,但是它在做什么?
如果我加载一个我用Paint创建的图像说大小相同,并在屏幕上显示它就像我预期的那样工作,一半在屏幕上,一半关闭。
我开始的原始图像就在这里。
我要做的是只显示屏幕上的第一个数字,以便应用程序的用户可以侧向滚动到第二个数字。滚动我工作,一些修复要做。如果我上传具有正确尺寸[2 x宽度,相同高度]的预设图像,它就可以工作。但是,如果我上传的图像是一个子集,请尝试裁剪+组合它,不管它不起作用。
刚刚添加了一条左侧的代码,另一条也许是呐喊......仍然无法正常工作。我创建的第一个图像确切的大小工作,它看起来像这样......
原件看起来像这样......
答案 0 :(得分:1)
我认为你正在混合图像尺寸,所需图像尺寸,屏幕/视图尺寸......
在游乐场试试......我添加了名为“orig2048x1024.png”的2048x768“1 2”图片
<uses-permission android:name="android.permission.RECORD_AUDIO" ></uses-permission>