2017-04-01 8 views
1

私は以下のコードに従っていますし、image.whatが間違っているのを表示していませんか?私はnewimage show nilをデバッグしようとしていました。スウィフト3.0で画像に緯度と経度を書き込む方法は?

私は任意のヘルプが

func textOnImage(text: NSString, atPoint: CGPoint,capturedImage:UIImage?) -> UIImage?{ 

     if let capturedImage = capturedImage{ 

      // Setup the font specific variables 
      let textColor = UIColor.white 
      let textFont = UIFont(name: "Helvetica", size: 14)! 

      // Setup the image context using the passed image 


      let scale = UIScreen.main.scale 

      UIGraphicsBeginImageContextWithOptions(capturedImage.size, false, scale) 



      // Setup the font attributes that will be later used to dictate how the text should be drawn 
      let textFontAttributes = [ 
       NSFontAttributeName: textFont, 
       NSForegroundColorAttributeName: textColor, 
       ] as [String : Any] 

      // Create a point within the space that is as bit as the image 


      let rect = CGRect(x: atPoint.x, y: atPoint.y, width: capturedImage.size.width, height: capturedImage.size.height) 

      // Draw the text into an image 

      text.draw(in: rect, withAttributes: textFontAttributes) 



      // Create a new image out of the images we have created 
      let newImage = UIGraphicsGetImageFromCurrentImageContext() 

      // End the context now that we have the image we need 
      UIGraphicsEndImageContext() 
//Pass the image back up to the caller 
      return newImage! 

     } 
     return nil 

    } 
+0

が欠落している画像フレームのように見えるようなので、あなたの方法に見える

capturedImage.draw(in: CGRect(x: 0, y: 0, width: capturedImage.size.width, height:capturedImage.size.height)) 

線の下に含めます。 – adarshaU

+0

を確認してください可能性がある場所を教えてください。 – Mickel

答えて

0

をいただければ幸いですit.soを解決することができませんでしたが

func textOnImage(text: NSString, atPoint: CGPoint,capturedImage:UIImage?) -> UIImage?{ 

     if let capturedImage = capturedImage{ 

      // Setup the font specific variables 
      let textColor = UIColor.white 
      let textFont = UIFont(name: "Helvetica", size: 14)! 

      // Setup the image context using the passed image 


      let scale = UIScreen.main.scale 

      UIGraphicsBeginImageContextWithOptions(capturedImage.size, false, scale) 



      // Setup the font attributes that will be later used to dictate how the text should be drawn 
      let textFontAttributes = [ 
       NSFontAttributeName: textFont, 
       NSForegroundColorAttributeName: textColor, 
       ] as [String : Any] 



      capturedImage.draw(in: CGRect(x: 0, y: 0, width: capturedImage.size.width, height:capturedImage.size.height)) 



      // Create a point within the space that is as bit as the image 


      let rect = CGRect(x: atPoint.x, y: atPoint.y, width: capturedImage.size.width, height: capturedImage.size.height) 

      // Draw the text into an image 

      text.draw(in: rect, withAttributes: textFontAttributes) 



      // Create a new image out of the images we have created 
      let newImage = UIGraphicsGetImageFromCurrentImageContext() 

      // End the context now that we have the image we need 
      UIGraphicsEndImageContext() 

      //Pass the image back up to the caller 
      return newImage! 

     } 
     return nil 

    } 

} 
+0

ありがとうございました。出来た – Mickel

関連する問題