Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 合并两个图像&;最终图像上的文本_Swift_Uiimage_Swift3_Core Graphics - Fatal编程技术网

Swift 合并两个图像&;最终图像上的文本

Swift 合并两个图像&;最终图像上的文本,swift,uiimage,swift3,core-graphics,Swift,Uiimage,Swift3,Core Graphics,我在Swift中尝试的是将两个图像合并在一起,我正在合并的图像是我用触摸手势将一个图像拖到另一个图像上。我将图像合成,但我在主图像顶部拖动的图像无法保持其位置。我如何让它停留在我为复合材料放置它的地方 这是我的密码: extension CIHHatSelectionViewController{ // Return composite image of image2 overlayed on image1 // func compositeImage(_ image1: UIImage, im

我在Swift中尝试的是将两个图像合并在一起,我正在合并的图像是我用触摸手势将一个图像拖到另一个图像上。我将图像合成,但我在主图像顶部拖动的图像无法保持其位置。我如何让它停留在我为复合材料放置它的地方

这是我的密码:

extension CIHHatSelectionViewController{
// Return composite image of image2 overlayed on image1
//
func compositeImage(_ image1: UIImage, image2: UIImage, drawText: String, imageView1: CGPoint, imageView2:CGRect) -> UIImage {
    let catPos = (image1.size.height - imageView2.origin.y) - imageView2.height
    let bounds1 = CGRect(x: 0, y: 0, width: image1.size.width, height: image1.size.height)
    let bounds2 = CGRect(x:imageView2.origin.x, y:catPos, width:imageView2.size.width, height:imageView2.size.height)
    _ = CGColorSpaceCreateDeviceRGB()
    let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue)
    let ctx = CGContext(data: nil,
                        width: image1.cgImage!.width,
                        height: image1.cgImage!.height,
                        bitsPerComponent: image1.cgImage!.bitsPerComponent,
                        bytesPerRow: image1.cgImage!.bytesPerRow,
                        space: image1.cgImage!.colorSpace!,
                        bitmapInfo: bitmapInfo.rawValue)!
    ctx.draw(image1.cgImage!, in: bounds1, byTiling: false)
    ctx.setBlendMode(.normal) // one image over the other
    ctx.draw(image2.cgImage!, in: bounds2, byTiling: false)

    let finalImage = textToImage(drawText, inImage: UIImage(cgImage: ctx.makeImage()!), atPoint: imageView1)
    return finalImage
}