Ich möchte Unschärfe-Effekt in UIimage hinzufügen, nicht UIImage View. kann ich Unschärfe-Effekt in UIImage Ansicht wie hinzufügen:Wie fügt man Swift-Effekt in UIImage mit Swift hinzu?
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = img.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
img.addSubview(blurEffectView)
Aber ich möchte wirklich in UIImage hinzuzufügen. Weil ich Bild mit Text zeichnen muss. also hier ist meine Funktion:
func textToImageWithPhoto(drawText text: NSString, inImage image: UIImage, atPoint point: CGPoint) -> UIImage {
let scale = UIScreen.main.scale
UIGraphicsBeginImageContextWithOptions(CGSize.init(width: 375, height: 375), false, scale)
image.draw(in: CGRect(origin: CGPoint.init(x: 0, y: -100), size: CGSize(width: 375, height: 375*1.5)))
let rect = CGRect(origin: CGPoint.init(x: 0, y: 187.5 - 150/2), size: CGSize.init(width: 375, height: 375))
text.draw(in: rect, withAttributes: textFontAttributes)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.saveData(img: newImage!, text: self.quotesTxt.text!) //SAVE CORE DATA
return newImage!
}
Und gibt es eine Möglichkeit, Unschärfe-Effekt innerhalb der Zeichenfunktion hinzuzufügen?
Visite hier [Verwischung & Tönung Bild] ((https://developer.apple.com/library/content/samplecode/UIImageEffects/Listings/UIImageEffects_UIImageEffects_h.html#//apple_ref/doc/uid/DTS40013396-UIImageEffects_UIImageEffects_h-DontLinkElementID_8) –
Nach dem Hinzufügen von Text auf Ihrem Bild beim Zurückgeben eines neuen Bildes tun Sie dies vor 'verschwommenesImage = UIImageEffects.imageByApplyingLightEffect (zu: newImage)' –
@Mukesh Danke! Aber, wenn ich Unschärfe Bild hinzufügen, Bildgröße geändert wird! Ich möchte Bildgröße beibehalten. Wie repariere ich es? –