0
目前,我可以在頂部保存帶有圖像的照片,但是頂部圖像不在預覽屏幕上顯示的座標上視圖。如何使用Swift正確地在照片上放置圖像視圖
fileprivate func mergeUIViews() -> UIImage?
{
let bottomImage = photo
let topImage = uiViewInstance.image
let bottomImageHeight = bottomImage.size.height
let bottomImageWidth = bottomImage.size.width
let topImageHeight = uiViewInstance.frame.height
let topImageWidth = uiViewInstance.frame.width
let topImageOrigin = uiViewInstance.frame.origin
let bottomImageSize = CGSize(width: bottomImageWidth, height: bottomImageHeight)
let topImageSize = CGSize(width: topImageWidth, height: topImageHeight)
// Merge images
UIGraphicsBeginImageContextWithOptions(bottomImageSize, false, 0.0)
bottomImage.draw(in: CGRect(origin: CGPoint.zero, size: bottomImageSize))
topImage .draw(in: CGRect(origin: topImageOrigin, size: topImageSize)) // Where I believe the problem exists
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
您打印過'uiViewInstance.frame.origin'嗎?它是你期望的CGPoint嗎? – Ryan
@Ryan在故事板中,我將頂部圖像水平和垂直設置在中心進行測試。但是,一旦運行此代碼,合併的圖像被保存到照片庫,頂部圖像出現在左上角,水平和垂直間距都很小 – lifewithelliott
愚蠢的問題,但是您檢查了newImage的外觀?它是否有可能具有(0,0)原點的頂部圖像? – dfd